Skip to content

Commit bc0108a

Browse files
author
Stephane Royer
committed
TraceLevel => EtlTraceLevel
1 parent dec9dbe commit bc0108a

File tree

448 files changed

+15752
-16803
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

448 files changed

+15752
-16803
lines changed

src/Paillave.EntityFrameworkCoreExtension/BulkSave/BulkSaveEngine.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@
88

99
namespace Paillave.EntityFrameworkCoreExtension.BulkSave;
1010

11-
public class BulkSaveEngine<T> : BulkSaveEngineBase<T> where T : class
11+
public class BulkSaveEngine<T>(DbContext context, params Expression<Func<T, object>>[] pivotKeys) : BulkSaveEngineBase<T>(context, pivotKeys) where T : class
1212
{
13-
public BulkSaveEngine(DbContext context, params Expression<Func<T, object>>[] pivotKeys) : base(context, pivotKeys)
14-
{
15-
}
16-
1713
protected override SaveContextQueryBase<T> CreateSaveContextQueryInstance(DbContext context, string? schema, string table, List<IProperty> propertiesToInsert, List<IProperty> propertiesToUpdate, List<List<IProperty>> propertiesForPivotSet, List<IProperty> propertiesToBulkLoad, List<IEntityType> entityTypes, CancellationToken cancellationToken)
1814
{
1915
if (context.Database.IsSqlServer())

src/Paillave.EntityFrameworkCoreExtension/BulkSave/BulkSaveEngineBase.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ namespace Paillave.EntityFrameworkCoreExtension.BulkSave;
1313

1414
public abstract class BulkSaveEngineBase<T> : IDisposable where T : class
1515
{
16-
private List<IProperty> _propertiesToInsert; // any column except computed
17-
private List<IProperty> _propertiesToUpdate; // any column except pivot, computed
16+
private readonly List<IProperty> _propertiesToInsert; // any column except computed
17+
private readonly List<IProperty> _propertiesToUpdate; // any column except pivot, computed
1818
// private HashSet<string> _propertiesNotToBeUpdatedToNull = new HashSet<string>();
19-
private List<List<IProperty>> _propertiesForPivotSet; // pivot columns
19+
private readonly List<List<IProperty>> _propertiesForPivotSet; // pivot columns
2020
// private List<IProperty> _propertiesForPivot; // pivot columns
21-
private List<IProperty> _propertiesToGetAfterSetInTarget; // computed, and with default value column
22-
private List<IProperty> _propertiesToBulkLoad; // any column except computed that is not pivot
23-
private List<IEntityType> _entityTypes;
21+
private readonly List<IProperty> _propertiesToGetAfterSetInTarget; // computed, and with default value column
22+
private readonly List<IProperty> _propertiesToBulkLoad; // any column except computed that is not pivot
23+
private readonly List<IEntityType> _entityTypes;
2424

2525
protected StoreObjectIdentifier StoreObject { get; }
26-
private string? _schema;
27-
private string _table;
26+
private readonly string? _schema;
27+
private readonly string _table;
2828
private bool disposedValue;
2929
private readonly DbContext _context;
3030
protected abstract SaveContextQueryBase<T> CreateSaveContextQueryInstance(DbContext context, string? schema, string table, List<IProperty> propertiesToInsert, List<IProperty> propertiesToUpdate, List<List<IProperty>> propertiesForPivotSet, List<IProperty> propertiesToBulkLoad, List<IEntityType> entityTypes, CancellationToken cancellationToken);

src/Paillave.EntityFrameworkCoreExtension/BulkSave/BulkUpdateEngine.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88

99
namespace Paillave.EntityFrameworkCoreExtension.BulkSave;
1010

11-
public class BulkUpdateEngine<TEntity, TSource> : BulkUpdateEngineBase<TEntity, TSource> where TEntity : class
11+
public class BulkUpdateEngine<TEntity, TSource>(DbContext context, Expression<Func<TSource, TEntity>> updateKey, Expression<Func<TSource, TEntity>> updateValues) : BulkUpdateEngineBase<TEntity, TSource>(context, updateKey, updateValues) where TEntity : class
1212
{
13-
public BulkUpdateEngine(DbContext context, Expression<Func<TSource, TEntity>> updateKey, Expression<Func<TSource, TEntity>> updateValues)
14-
: base(context, updateKey, updateValues) { }
15-
1613
protected override UpdateContextQueryBase<TSource> CreateUpdateContextQueryInstance(DbContext context, string? schema, string table, List<IProperty> propertiesToUpdate, List<IProperty> propertiesForPivot, List<IProperty> propertiesToBulkLoad, IEntityType baseType, IDictionary<string, MemberInfo> propertiesGetter)
1714
{
1815
if (context.Database.IsSqlServer())

src/Paillave.EntityFrameworkCoreExtension/BulkSave/BulkUpdateEngineBase.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ namespace Paillave.EntityFrameworkCoreExtension.BulkSave;
1212

1313
public abstract class BulkUpdateEngineBase<T, TSource> where T : class
1414
{
15-
private List<IProperty> _propertiesToUpdate; // any column except pivot, computed
16-
private List<IProperty> _propertiesForPivot; // pivot columns
17-
private List<IProperty> _propertiesToBulkLoad; // any column except computed that is not pivot
18-
private IDictionary<string, MemberInfo> _propertyGetters;
19-
private IEntityType _baseType;
15+
private readonly List<IProperty> _propertiesToUpdate; // any column except pivot, computed
16+
private readonly List<IProperty> _propertiesForPivot; // pivot columns
17+
private readonly List<IProperty> _propertiesToBulkLoad; // any column except computed that is not pivot
18+
private readonly IDictionary<string, MemberInfo> _propertyGetters;
19+
private readonly IEntityType _baseType;
2020
protected StoreObjectIdentifier StoreObject { get; }
2121

22-
private string? _schema;
23-
private string _table;
22+
private readonly string? _schema;
23+
private readonly string _table;
2424
private readonly DbContext _context;
2525
protected abstract UpdateContextQueryBase<TSource> CreateUpdateContextQueryInstance(DbContext context, string? schema, string table, List<IProperty> propertiesToUpdate, List<IProperty> propertiesForPivot, List<IProperty> propertiesToBulkLoad, IEntityType baseType, IDictionary<string, MemberInfo> propertiesGetter);
2626
private IEnumerable<IEntityType> GetAllRelatedEntityTypes(IEntityType et)

src/Paillave.EntityFrameworkCoreExtension/BulkSave/ObjectDataReader.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,11 @@ namespace Paillave.EntityFrameworkCoreExtension.BulkSave;
1212

1313
public class ObjectDataReader : IDataReader
1414
{
15-
private class ValueAccessor
15+
private class ValueAccessor(Type type)
1616
{
17-
private HashSet<string> _relatedProperties;
18-
private TypeAccessor _accessor;
17+
private readonly HashSet<string> _relatedProperties = new(type.GetProperties().Select(i => i.Name));
18+
private readonly TypeAccessor _accessor = TypeAccessor.Create(type);
1919

20-
public ValueAccessor(Type type)
21-
{
22-
_accessor = TypeAccessor.Create(type);
23-
_relatedProperties = new HashSet<string>(type.GetProperties().Select(i => i.Name));
24-
}
2520
public object? this[object target, string key]
2621
{
2722
get
@@ -41,7 +36,7 @@ public ValueAccessor(Type type)
4136
private readonly string[] _memberNames;
4237
private readonly Type[] _effectiveTypes;
4338
private readonly bool[] _allowNull;
44-
private string? _tempColumnNumOrderName;
39+
private readonly string? _tempColumnNumOrderName;
4540
private int _rowCounter = 0;
4641
public ObjectDataReader(IEnumerable source, ObjectDataReaderConfig config)
4742
{
@@ -183,7 +178,7 @@ public IDataReader GetData(int i)
183178
{
184179
throw new NotImplementedException();
185180
}
186-
private Dictionary<string, Dictionary<string, bool>> _shadowOfEntityDico = new Dictionary<string, Dictionary<string, bool>>();
181+
private readonly Dictionary<string, Dictionary<string, bool>> _shadowOfEntityDico = new();
187182
public object this[string name]
188183
{
189184
get

src/Paillave.EntityFrameworkCoreExtension/BulkSave/SaveContextQueryBase.cs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,35 @@
77

88
namespace Paillave.EntityFrameworkCoreExtension.BulkSave;
99

10-
public abstract class SaveContextQueryBase<T> where T : class
10+
public abstract class SaveContextQueryBase<T>(DbContext context, string schema, string table, List<IProperty> propertiesToInsert, List<IProperty> propertiesToUpdate, List<List<IProperty>> propertiesForPivotSet, List<IProperty> propertiesToBulkLoad, List<IEntityType> entityTypes, CancellationToken cancellationToken, StoreObjectIdentifier storeObject) where T : class
1111
{
12-
protected string Table { get; }
13-
protected StoreObjectIdentifier StoreObject { get; }
12+
protected string Table { get; } = table;
13+
protected StoreObjectIdentifier StoreObject { get; } = storeObject;
1414
protected string StagingId { get; } = Guid.NewGuid().ToString().Substring(0, 8);
15-
protected string Schema { get; }
16-
protected List<IEntityType> EntityTypes { get; }
15+
protected string Schema { get; } = schema;
16+
protected List<IEntityType> EntityTypes { get; } = entityTypes;
1717

1818
/// <summary>
1919
/// Any column except computed
2020
/// </summary>
21-
protected List<IProperty> PropertiesToInsert { get; }
21+
protected List<IProperty> PropertiesToInsert { get; } = propertiesToInsert;
2222
/// <summary>
2323
/// any column except pivot, computed
2424
/// </summary>
25-
protected List<IProperty> PropertiesToUpdate { get; }
25+
protected List<IProperty> PropertiesToUpdate { get; } = propertiesToUpdate;
2626
/// <summary>
2727
/// pivot columns
2828
/// </summary>
29-
protected List<List<IProperty>> PropertiesForPivotSet { get; }
29+
protected List<List<IProperty>> PropertiesForPivotSet { get; } = propertiesForPivotSet;
3030

3131
/// <summary>
3232
/// Any column except computed that is not pivot
3333
/// </summary>
34-
protected List<IProperty> PropertiesToBulkLoad { get; }
34+
protected List<IProperty> PropertiesToBulkLoad { get; } = propertiesToBulkLoad;
3535

36-
protected CancellationToken CancellationToken { get; }
36+
protected CancellationToken CancellationToken { get; } = cancellationToken;
3737

38-
protected DbContext Context { get; }
39-
public SaveContextQueryBase(DbContext context, string schema, string table, List<IProperty> propertiesToInsert, List<IProperty> propertiesToUpdate, List<List<IProperty>> propertiesForPivotSet, List<IProperty> propertiesToBulkLoad, List<IEntityType> entityTypes, CancellationToken cancellationToken, StoreObjectIdentifier storeObject)
40-
{
41-
this.StoreObject = storeObject;
42-
this.CancellationToken = cancellationToken;
43-
this.PropertiesToInsert = propertiesToInsert;
44-
this.PropertiesToUpdate = propertiesToUpdate;
45-
this.PropertiesForPivotSet = propertiesForPivotSet;
46-
this.PropertiesToBulkLoad = propertiesToBulkLoad;
47-
this.Schema = schema;
48-
this.Table = table;
49-
this.Context = context;
50-
this.EntityTypes = entityTypes;
51-
}
38+
protected DbContext Context { get; } = context;
5239

5340
/// <summary>
5441
/// Create the staging that is meant to receive the raw bulk load
@@ -84,7 +71,7 @@ protected DataTable StrictlyExecuteSql(string sqlQuery)
8471
cmd.CommandType = System.Data.CommandType.Text;
8572
cmd.CommandText = sqlQuery;
8673
var dataReader = cmd.ExecuteReader();
87-
DataTable dataTable = new DataTable();
74+
DataTable dataTable = new();
8875
dataTable.Load(dataReader);
8976
// https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/queries-in-linq-to-dataset
9077
return dataTable;

src/Paillave.EntityFrameworkCoreExtension/BulkSave/SqlServer/SqlServerSaveContextQuery.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@
99

1010
namespace Paillave.EntityFrameworkCoreExtension.BulkSave.SqlServer;
1111

12-
public class SqlServerSaveContextQuery<T> : SaveContextQueryBase<T> where T : class
12+
public class SqlServerSaveContextQuery<T>(DbContext Context, string? schema, string table, List<IProperty> propertiesToInsert, List<IProperty> propertiesToUpdate, List<List<IProperty>> propertiesForPivotSet, List<IProperty> propertiesToBulkLoad, List<IEntityType> entityTypes, CancellationToken cancellationToken, StoreObjectIdentifier storeObject) : SaveContextQueryBase<T>(Context, schema ?? "dbo", table, propertiesToInsert, propertiesToUpdate, propertiesForPivotSet, propertiesToBulkLoad, entityTypes, cancellationToken, storeObject) where T : class
1313
{
1414
private const string TempColumnNumOrderName = "_TempColumnNumOrder";
1515
private const string TempColumnAction = "_Action";
1616
private string SqlTargetTable => $"[{this.Schema}].[{this.Table}]";
1717
private string SqlStagingTableName => $"[{this.Schema}].[{this.Table}_temp_{this.StagingId}]";
1818
private string SqlOutputStagingTableName => $"[{this.Schema}].[{this.Table}_tempoutput_{this.StagingId}]";
1919

20-
public SqlServerSaveContextQuery(DbContext Context, string? schema, string table, List<IProperty> propertiesToInsert, List<IProperty> propertiesToUpdate, List<List<IProperty>> propertiesForPivotSet, List<IProperty> propertiesToBulkLoad, List<IEntityType> entityTypes, CancellationToken cancellationToken, StoreObjectIdentifier storeObject)
21-
: base(Context, schema ?? "dbo", table, propertiesToInsert, propertiesToUpdate, propertiesForPivotSet, propertiesToBulkLoad, entityTypes, cancellationToken, storeObject)
22-
{
23-
}
24-
2520
public override int CreateStagingTable()
2621
=> this.Context.Database.ExecuteSqlRaw(this.CreateStagingTableSql());
2722

src/Paillave.EntityFrameworkCoreExtension/BulkSave/SqlServer/SqlServerUpdateContextQuery.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@
88
using System.Reflection;
99

1010
namespace Paillave.EntityFrameworkCoreExtension.BulkSave.SqlServer;
11-
public class SqlServerUpdateContextQuery<T> : UpdateContextQueryBase<T>
11+
public class SqlServerUpdateContextQuery<T>(DbContext context, string? schema, string table, List<IProperty> propertiesToUpdate, List<IProperty> propertiesForPivot, List<IProperty> propertiesToBulkLoad, IEntityType baseType, IDictionary<string, MemberInfo> propertiesGetter, StoreObjectIdentifier storeObject) : UpdateContextQueryBase<T>(context, schema ?? "dbo", table, propertiesToUpdate, propertiesForPivot, propertiesToBulkLoad, baseType, propertiesGetter, storeObject)
1212
{
1313
private string SqlTargetTable => $"[{this.Schema}].[{this.Table}]";
1414
private string SqlStagingTableName => $"[{this.Schema}].[{this.Table}_temp_{this.StagingId}]";
1515

16-
public SqlServerUpdateContextQuery(DbContext context, string? schema, string table, List<IProperty> propertiesToUpdate, List<IProperty> propertiesForPivot, List<IProperty> propertiesToBulkLoad, IEntityType baseType, IDictionary<string, MemberInfo> propertiesGetter, StoreObjectIdentifier storeObject)
17-
: base(context, schema ?? "dbo", table, propertiesToUpdate, propertiesForPivot, propertiesToBulkLoad, baseType, propertiesGetter, storeObject)
18-
{
19-
}
20-
2116
protected virtual string CreateStagingTableSql()
2217
=> $@"SELECT TOP 0 {string.Join(",", PropertiesToBulkLoad.Select(i => $"T.{i.GetColumnName(base.StoreObject)}"))}
2318
INTO {SqlStagingTableName} FROM {SqlTargetTable} AS T

src/Paillave.EntityFrameworkCoreExtension/BulkSave/UpdateContextQueryBase.cs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,29 @@
66

77
namespace Paillave.EntityFrameworkCoreExtension.BulkSave;
88

9-
public abstract class UpdateContextQueryBase<TSource>
9+
public abstract class UpdateContextQueryBase<TSource>(DbContext context, string schema, string table, List<IProperty> propertiesToUpdate, List<IProperty> propertiesForPivot, List<IProperty> propertiesToBulkLoad, IEntityType baseType, IDictionary<string, MemberInfo> propertyGetters, StoreObjectIdentifier storeObject)
1010
{
11-
protected string Table { get; }
11+
protected string Table { get; } = table;
1212
protected string StagingId { get; } = Guid.NewGuid().ToString().Substring(0, 8);
13-
protected string Schema { get; }
14-
protected IEntityType BaseType { get; }
15-
protected StoreObjectIdentifier StoreObject { get; }
16-
protected IDictionary<string, MemberInfo> PropertyGetters { get; }
13+
protected string Schema { get; } = schema;
14+
protected IEntityType BaseType { get; } = baseType;
15+
protected StoreObjectIdentifier StoreObject { get; } = storeObject;
16+
protected IDictionary<string, MemberInfo> PropertyGetters { get; } = propertyGetters;
1717
/// <summary>
1818
/// any column except pivot, computed
1919
/// </summary>
20-
protected List<IProperty> PropertiesToUpdate { get; }
20+
protected List<IProperty> PropertiesToUpdate { get; } = propertiesToUpdate;
2121
/// <summary>
2222
/// pivot columns
2323
/// </summary>
24-
protected List<IProperty> PropertiesForPivot { get; }
24+
protected List<IProperty> PropertiesForPivot { get; } = propertiesForPivot;
2525

2626
/// <summary>
2727
/// Any column except computed that is not pivot
2828
/// </summary>
29-
protected List<IProperty> PropertiesToBulkLoad { get; }
29+
protected List<IProperty> PropertiesToBulkLoad { get; } = propertiesToBulkLoad;
3030

31-
protected DbContext Context { get; }
32-
public UpdateContextQueryBase(DbContext context, string schema, string table, List<IProperty> propertiesToUpdate, List<IProperty> propertiesForPivot, List<IProperty> propertiesToBulkLoad, IEntityType baseType, IDictionary<string, MemberInfo> propertyGetters, StoreObjectIdentifier storeObject)
33-
{
34-
this.StoreObject = storeObject;
35-
this.PropertiesToUpdate = propertiesToUpdate;
36-
this.PropertiesForPivot = propertiesForPivot;
37-
this.PropertiesToBulkLoad = propertiesToBulkLoad;
38-
this.PropertyGetters = propertyGetters;
39-
40-
this.Schema = schema;
41-
this.Table = table;
42-
this.Context = context;
43-
this.BaseType = baseType;
44-
}
31+
protected DbContext Context { get; } = context;
4532

4633
/// <summary>
4734
/// Create the staging that is meant to receive the raw bulk load

0 commit comments

Comments
 (0)