Skip to content

Commit

Permalink
Merge pull request #518 from paillave/dotnet9-migration
Browse files Browse the repository at this point in the history
Refactor to enable nullable reference types and add AzureBlobOptions with IFileSaver interface
  • Loading branch information
paillave authored Dec 19, 2024
2 parents 57ba031 + ceb0497 commit 54dc05f
Show file tree
Hide file tree
Showing 78 changed files with 1,240 additions and 683 deletions.
8 changes: 4 additions & 4 deletions documentation/docs/recipes/2_normalize.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ The file would look like the following:

```csv title="post.csv"
title,author,email,timestamp,category,link,post
FundProcess features,Stéphane Royer,stephane.royer@fundprocess.lu,20210109113005,Category 2,https://www.fundprocess.lu/features/,
coucou features,Stéphane Royer,stephane.royer@coucou.lu,20210109113005,Category 2,https://www.coucou.lu/features/,
ETL.NET revealed,Paillave,[email protected],20210508181126,Category 2,,"This a post, about ETL.NET"
ETL.NET page,Paillave,[email protected],20210504164510,Category 1,https://paillave.github.io/Etl.Net/,
FundProcess presentation,Stéphane Royer,stephane.royer@fundprocess.lu,20210203124051,Category 2,,"This a ""post"", about FundProcess"
FundProcess website,Stéphane Royer,stephane.royer@fundprocess.lu,20210106103005,Category 1,http://www.fundprocess.lu,
coucou presentation,Stéphane Royer,stephane.royer@coucou.lu,20210203124051,Category 2,,"This a ""post"", about coucou"
coucou website,Stéphane Royer,stephane.royer@coucou.lu,20210106103005,Category 1,http://www.coucou.lu,
ETL.NET nuget,Paillave,[email protected],20200504164510,Category 1,http://www.nuget.org/packages/Etl.Net,
ETL.NET information,Paillave,[email protected],20200518071024,Category 3,,"This ""another post"" about ETL.NET"
FundProcess information,Stéphane Royer,stephane.royer@fundprocess.lu,20210819124550,Category 1,,This another post about FundProcess
coucou information,Stéphane Royer,stephane.royer@coucou.lu,20210819124550,Category 1,,This another post about coucou
```

The normalized structure where this file must be imported is this one:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public BulkSaveEngine(DbContext context, params Expression<Func<T, object>>[] pi
{
}

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)
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)
{
if (context.Database.IsSqlServer())
return new SqlServerSaveContextQuery<T>(context, schema, table, propertiesToInsert, propertiesToUpdate, propertiesForPivotSet, propertiesToBulkLoad, entityTypes, cancellationToken, base.StoreObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public abstract class BulkSaveEngineBase<T> : IDisposable where T : class
private List<IEntityType> _entityTypes;

protected StoreObjectIdentifier StoreObject { get; }
private string _schema;
private string? _schema;
private string _table;
private bool disposedValue;
private readonly DbContext _context;
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);
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);
private IEnumerable<IEntityType> GetAllRelatedEntityTypes(IEntityType et)
{
yield return et;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BulkUpdateEngine<TEntity, TSource> : BulkUpdateEngineBase<TEntity,
public BulkUpdateEngine(DbContext context, Expression<Func<TSource, TEntity>> updateKey, Expression<Func<TSource, TEntity>> updateValues)
: base(context, updateKey, updateValues) { }

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)
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)
{
if (context.Database.IsSqlServer())
return new SqlServerUpdateContextQuery<TSource>(context, schema, table, propertiesToUpdate, propertiesForPivot, propertiesToBulkLoad, baseType, propertiesGetter, base.StoreObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public abstract class BulkUpdateEngineBase<T, TSource> where T : class
private IEntityType _baseType;
protected StoreObjectIdentifier StoreObject { get; }

private string _schema;
private string? _schema;
private string _table;
private readonly DbContext _context;
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);
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);
private IEnumerable<IEntityType> GetAllRelatedEntityTypes(IEntityType et)
{
yield return et;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ namespace Paillave.EntityFrameworkCoreExtension.BulkSave;

public class Constants
{
public static object? DBNull = System.DBNull.Value;
public static object DBNull = System.DBNull.Value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public IDataReader GetData(int i)
throw new NotImplementedException();
}
private Dictionary<string, Dictionary<string, bool>> _shadowOfEntityDico = new Dictionary<string, Dictionary<string, bool>>();
public object? this[string name]
public object this[string name]
{
get
{
Expand All @@ -200,35 +200,36 @@ public object? this[string name]
if (subDic.TryGetValue(name, out var hasIt))
{
if (hasIt)
return etr.Property(name).CurrentValue;
return etr.Property(name).CurrentValue ?? Constants.DBNull;
else
return null;
return Constants.DBNull;
}
var elt = etr.Properties.FirstOrDefault(i => i.Metadata.Name == name);
subDic[name] = elt != null;
if (elt != null)
return elt.CurrentValue;
return elt.CurrentValue ?? Constants.DBNull;
else
return null;
return Constants.DBNull;
}
var elt2 = etr.Properties.FirstOrDefault(i => i.Metadata.Name == name);
_shadowOfEntityDico[etr.Metadata.Name] = new Dictionary<string, bool> { [name] = elt2 != null };
if (elt2 == null) return null;
return elt2.CurrentValue;
if (elt2 == null) return Constants.DBNull;
return elt2.CurrentValue ?? Constants.DBNull;
// if(etr.Properties.FirstOrDefault())
// return etr.Property(name).CurrentValue;
}
else
{
if (_currentType == null) throw new Exception("No current item");
if (!_accessorsByType.TryGetValue(_currentType, out var acc)) return Constants.DBNull;
var val = acc[Current, name];
if (val == null) return Constants.DBNull;
if (_convertibleProperties.TryGetValue(name, out var converter)) return converter.ConvertToProvider(val);
if (_convertibleProperties.TryGetValue(name, out var converter)) return converter.ConvertToProvider(val) ?? Constants.DBNull;
return val;
}
}
}
public object? this[int i] => this[_memberNames[i]] ?? Constants.DBNull;
public object this[int i] => this[_memberNames[i]];
}
public class ObjectDataReaderConfig
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SqlServerSaveContextQuery<T> : SaveContextQueryBase<T> where T : cl
private string SqlStagingTableName => $"[{this.Schema}].[{this.Table}_temp_{this.StagingId}]";
private string SqlOutputStagingTableName => $"[{this.Schema}].[{this.Table}_tempoutput_{this.StagingId}]";

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)
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)
: base(Context, schema ?? "dbo", table, propertiesToInsert, propertiesToUpdate, propertiesForPivotSet, propertiesToBulkLoad, entityTypes, cancellationToken, storeObject)
{
}
Expand Down Expand Up @@ -159,7 +159,7 @@ private string GetWhenMatchedMergeStatement(HashSet<string> pivotColumns, bool d
}
protected virtual string MergeFromStagingSql(bool doNotUpdateIfExists = false)
{
var pivotColumns = PropertiesForPivotSet.SelectMany(p => p.Select(i => i.GetColumnName(base.StoreObject)).Where(i => !string.IsNullOrWhiteSpace(i)).Select(i => i!)).ToHashSet();
var pivotColumns = PropertiesForPivotSet.SelectMany(p => p.Select(i => i.GetColumnName(base.StoreObject)).Where(i => !string.IsNullOrWhiteSpace(i)).Cast<string>()).ToHashSet();
string whenNotMatchedStatement = $@"WHEN NOT MATCHED BY TARGET THEN
INSERT ({string.Join(", ", PropertiesToInsert.Select(i => $"[{i.GetColumnName(base.StoreObject)}]"))})
VALUES ({string.Join(", ", PropertiesToInsert.Select(i => $"S.[{i.GetColumnName(base.StoreObject)}]"))})";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class SqlServerUpdateContextQuery<T> : UpdateContextQueryBase<T>
private string SqlTargetTable => $"[{this.Schema}].[{this.Table}]";
private string SqlStagingTableName => $"[{this.Schema}].[{this.Table}_temp_{this.StagingId}]";

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)
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)
: base(context, schema ?? "dbo", table, propertiesToUpdate, propertiesForPivot, propertiesToBulkLoad, baseType, propertiesGetter, storeObject)
{
}
Expand Down
Loading

0 comments on commit 54dc05f

Please sign in to comment.