Skip to content

Commit d5ccc49

Browse files
Update source
Update source
1 parent ab0166b commit d5ccc49

File tree

7 files changed

+82
-27
lines changed

7 files changed

+82
-27
lines changed

src/shared/Z.EF.Plus.Audit.Shared/AuditConfiguration/FormatValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public string FormatValue(object entity, string propertyName, object currentValu
3636
public string FormatValue(object entity, string propertyName, object currentValue)
3737
#endif
3838
{
39-
if (EntityValueFormatters.Count > 0)
39+
if (entity != null && EntityValueFormatters.Count > 0)
4040
{
4141
var type = entity.GetType();
4242
var key = string.Concat(type.FullName, ";", propertyName);

src/shared/Z.EF.Plus.Audit.Shared/AuditEntryProperty.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ public void Build(AuditEntry parent, string relationName, string propertyName, o
127127
if (PropertyName == null)
128128
{
129129
#if EF5 || EF6
130-
PropertyName = parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory != null ?
130+
PropertyName = parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory != null && parent.Entry.Entity != null ?
131131
parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory(ObjectContext.GetObjectType(parent.Entry.Entity.GetType()), propertyName) :
132132
propertyName;
133133
#elif EFCORE
134-
PropertyName = parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory != null ?
134+
PropertyName = parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory != null && parent.Entry.Entity != null ?
135135
parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory(parent.Entry.Entity.GetType(), propertyName) :
136136
propertyName;
137137
#endif

src/shared/Z.EF.Plus.BatchDelete.Shared/BatchDelete.cs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public int Execute<T>(IQueryable<T> query) where T : class
191191
var dbContext = query.GetDbContext();
192192

193193
#if EF6
194-
if (dbContext.IsInMemoryEffortQueryContext())
194+
if (dbContext.IsInMemoryEffortQueryContext() || BatchDeleteManager.IsInMemoryQuery)
195195
{
196196
var context = query.GetDbContext();
197197

@@ -637,21 +637,38 @@ public DbCommand CreateCommand(IQueryable query, IEntityType entity)
637637
}
638638
else if (isMySqlPomelo)
639639
{
640-
var sqlServer = (IRelationalEntityTypeAnnotations)dynamicProviderEntityType.Invoke(null, new[] { entity });
640+
if (dynamicProviderEntityType == null)
641+
{
642+
// GET mapping
643+
tableName = string.Concat("`", entity.Relational().TableName, "`");
641644

642-
// GET mapping
643-
tableName = string.Concat("`", sqlServer.TableName, "`");
645+
// GET keys mappings
646+
foreach (var propertyKey in entity.GetKeys().ToList()[0].Properties)
647+
{
648+
columnKeys.Add(propertyKey.Relational().ColumnName);
649+
}
644650

645-
// GET keys mappings
646-
foreach (var propertyKey in entity.GetKeys().ToList()[0].Properties)
651+
primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.`", x, "` = B.`", x, "`")));
652+
}
653+
else
647654
{
648-
var mappingProperty = dynamicProviderProperty.Invoke(null, new[] { propertyKey });
655+
var sqlServer = (IRelationalEntityTypeAnnotations)dynamicProviderEntityType.Invoke(null, new[] { entity });
649656

650-
var columnNameProperty = mappingProperty.GetType().GetProperty("ColumnName", BindingFlags.Public | BindingFlags.Instance);
651-
columnKeys.Add((string)columnNameProperty.GetValue(mappingProperty));
652-
}
657+
// GET mapping
658+
tableName = string.Concat("`", sqlServer.TableName, "`");
653659

654-
primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.`", x, "` = B.`", x, "`")));
660+
// GET keys mappings
661+
foreach (var propertyKey in entity.GetKeys().ToList()[0].Properties)
662+
{
663+
var mappingProperty = dynamicProviderProperty.Invoke(null, new[] { propertyKey });
664+
665+
var columnNameProperty = mappingProperty.GetType().GetProperty("ColumnName", BindingFlags.Public | BindingFlags.Instance);
666+
columnKeys.Add((string)columnNameProperty.GetValue(mappingProperty));
667+
}
668+
669+
primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.`", x, "` = B.`", x, "`")));
670+
}
671+
655672
}
656673
else if (isMySql)
657674
{

src/shared/Z.EF.Plus.BatchDelete.Shared/BatchDeleteManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public class BatchDeleteManager
2424
/// <summary>Gets or sets the factory to create an InMemory DbContext.</summary>
2525
/// <value>The factory to create an InMemory DbContext.</value>
2626
public static Func<DbContext> InMemoryDbContextFactory { get; set; }
27+
#else
28+
/// <summary>
29+
/// Gets or sets a value indicating whether this object is in memory query.
30+
/// </summary>
31+
/// <value>True if this object is in memory query, false if not.</value>
32+
public static bool IsInMemoryQuery { get; set; }
2733
#endif
2834
}
2935
}

src/shared/Z.EF.Plus.BatchUpdate.Shared/BatchUpdate.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -729,23 +729,41 @@ public DbCommand CreateCommand(IQueryable query, IEntityType entity, List<Tuple<
729729
}
730730
else if (isMySqlPomelo)
731731
{
732-
var sqlServer = (IRelationalEntityTypeAnnotations)dynamicProviderEntityType.Invoke(null, new[] { entity });
732+
if (dynamicProviderEntityType == null)
733+
{
734+
// GET mapping
735+
tableName = string.Concat("`", entity.Relational().TableName, "`");
733736

734-
// GET mapping
735-
tableName = string.Concat("`", sqlServer.TableName, "`");
737+
// GET keys mappings
738+
var columnKeys = new List<string>();
739+
foreach (var propertyKey in entity.GetKeys().ToList()[0].Properties)
740+
{
741+
columnKeys.Add(propertyKey.Relational().ColumnName);
742+
}
736743

737-
// GET keys mappings
738-
var columnKeys = new List<string>();
739-
foreach (var propertyKey in entity.GetKeys().ToList()[0].Properties)
744+
// GET primary key join
745+
primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.`", x, "` = B.`", x, "`")));
746+
}
747+
else
740748
{
741-
var mappingProperty = dynamicProviderProperty.Invoke(null, new[] { propertyKey });
749+
var sqlServer = (IRelationalEntityTypeAnnotations)dynamicProviderEntityType.Invoke(null, new[] { entity });
742750

743-
var columnNameProperty = mappingProperty.GetType().GetProperty("ColumnName", BindingFlags.Public | BindingFlags.Instance);
744-
columnKeys.Add((string)columnNameProperty.GetValue(mappingProperty));
745-
}
751+
// GET mapping
752+
tableName = string.Concat("`", sqlServer.TableName, "`");
746753

747-
// GET primary key join
748-
primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.`", x, "` = B.`", x, "`")));
754+
// GET keys mappings
755+
var columnKeys = new List<string>();
756+
foreach (var propertyKey in entity.GetKeys().ToList()[0].Properties)
757+
{
758+
var mappingProperty = dynamicProviderProperty.Invoke(null, new[] { propertyKey });
759+
760+
var columnNameProperty = mappingProperty.GetType().GetProperty("ColumnName", BindingFlags.Public | BindingFlags.Instance);
761+
columnKeys.Add((string)columnNameProperty.GetValue(mappingProperty));
762+
}
763+
764+
// GET primary key join
765+
primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.`", x, "` = B.`", x, "`")));
766+
}
749767
}
750768
else if (isMySql)
751769
{

src/shared/Z.EF.Plus.QueryFilterInterceptor.Shared/QueryFilterInterceptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override DbExpression GetDbExpression(DbContext context, Type type)
3838
var typeFullName = type.AssemblyQualifiedName ?? type.FullName;
3939
var hookId = QueryFilterManager.PrefixHook + contextFullName + ";" + typeFullName + ";" + UniqueKey;
4040

41-
if (!QueryFilterManager.DbExpressionByHook.ContainsKey(hookId))
41+
if (!QueryFilterManager.DbExpressionByHook.ContainsKey(hookId) || !QueryFilterManager.DbExpressionParameterByHook.ContainsKey(QueryFilterManager.DbExpressionByHook[hookId]))
4242
{
4343
// CREATE set
4444
var setMethod = typeof(DbContext).GetMethod("Set", new Type[0]).MakeGenericMethod(type);

src/shared/Z.EF.Plus._Core.Shared/EF5_EF6/IQueryable`/IQueryable`.GetObjectQuery.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ internal static ObjectQuery<T> GetObjectQuery<T>(this IQueryable<T> query)
4545

4646
if (internalQueryProperty == null)
4747
{
48+
// Check if a InnerQuery on AutoMapper 3erd party library with field Inner.
49+
var innerField = query.GetType().GetField("inner", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase);
50+
51+
if (innerField != null)
52+
{
53+
var innerQuery = innerField.GetValue(query) as IQueryable<T>;
54+
55+
if (innerQuery != null && query != innerQuery)
56+
{
57+
var innerObjectQuery = innerQuery.GetObjectQuery();
58+
return innerObjectQuery;
59+
}
60+
}
61+
4862
// CHECK if a InnerQuery exists
4963
var innerQueryProperty = query.GetType().GetProperty("InnerQuery", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
5064

0 commit comments

Comments
 (0)