Skip to content

Commit 4e2544f

Browse files
author
zzzprojects
committed
Fix BatchDelete & BatchUpdate for .NET Core
Fix BatchDelete & BatchUpdate for .NET Core
1 parent 997447e commit 4e2544f

File tree

11 files changed

+65
-26
lines changed

11 files changed

+65
-26
lines changed

src/Z.EntityFramework.Plus.EF6/BatchDelete/BatchDelete.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,20 @@ public DbCommand CreateCommand(IQueryable query, IEntityType entity)
309309
#if NETSTANDARD1_3
310310
try
311311
{
312-
var assembly = Assembly.Load(new AssemblyName("EntityFramework.MicrosoftSqlServer, Version = 7.0.0.0, Culture = neutral, PublicKeyToken = adb9793829ddae60"));
312+
Assembly assembly;
313+
314+
try
315+
{
316+
assembly = Assembly.Load(new AssemblyName("Microsoft.EntityFrameworkCore.SqlServer"));
317+
}
318+
catch (Exception ex)
319+
{
320+
throw new Exception(ExceptionMessage.BatchOperations_AssemblyNotFound);
321+
}
313322

314323
if (assembly != null)
315324
{
316-
var type = assembly.GetType("Microsoft.Data.Entity.SqlServerMetadataExtensions");
325+
var type = assembly.GetType("Microsoft.EntityFrameworkCore.SqlServerMetadataExtensions");
317326

318327
var sqlServerEntityTypeMethod = type.GetMethod("SqlServer", new[] {typeof (IEntityType)});
319328
var sqlServerPropertyMethod = type.GetMethod("SqlServer", new[] {typeof (IProperty)});

src/Z.EntityFramework.Plus.EF6/BatchDelete/BatchDeleteManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class BatchDeleteManager
2323

2424
/// <summary>Gets or sets the factory to create an InMemory DbContext.</summary>
2525
/// <value>The factory to create an InMemory DbContext.</value>
26-
public static Func<DbContext> InMemoryDbContextFactory { get; set; }
26+
public static Func<DbContext> InMemoryDbContextFactory { get; set; }
2727
#endif
2828
}
2929
}

src/Z.EntityFramework.Plus.EF6/BatchUpdate/BatchUpdate.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,20 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
302302
public DbCommand CreateCommand(IQueryable query, IEntityType entity, List<Tuple<string, object>> values)
303303
{
304304
#if NETSTANDARD1_3
305-
var assembly = Assembly.Load(new AssemblyName("EntityFramework.MicrosoftSqlServer, Version = 7.0.0.0, Culture = neutral, PublicKeyToken = adb9793829ddae60"));
305+
Assembly assembly;
306+
307+
try
308+
{
309+
assembly = Assembly.Load(new AssemblyName("Microsoft.EntityFrameworkCore.SqlServer"));
310+
}
311+
catch (Exception ex)
312+
{
313+
throw new Exception(ExceptionMessage.BatchOperations_AssemblyNotFound);
314+
}
306315

307316
if (assembly != null)
308317
{
309-
var type = assembly.GetType("Microsoft.Data.Entity.SqlServerMetadataExtensions");
318+
var type = assembly.GetType("Microsoft.EntityFrameworkCore.SqlServerMetadataExtensions");
310319
var sqlServerEntityTypeMethod = type.GetMethod("SqlServer", new[] {typeof (IEntityType)});
311320
var sqlServerPropertyMethod = type.GetMethod("SqlServer", new[] {typeof (IProperty)});
312321
var sqlServer = (IRelationalEntityTypeAnnotations) sqlServerEntityTypeMethod.Invoke(null, new[] {entity});
@@ -447,26 +456,26 @@ public List<Tuple<string, object>> GetInnerValues<T>(IQueryable<T> query, Expres
447456

448457
try
449458
{
450-
assembly = Assembly.Load(new AssemblyName("EntityFramework.MicrosoftSqlServer, Version = 7.0.0.0, Culture = neutral, PublicKeyToken = adb9793829ddae60"));
459+
assembly = Assembly.Load(new AssemblyName("Microsoft.EntityFrameworkCore.SqlServer"));
451460
}
452-
catch (Exception)
461+
catch (Exception ex)
453462
{
454-
throw new Exception("");
463+
throw new Exception(ExceptionMessage.BatchOperations_AssemblyNotFound);
455464
}
456465

457466
if (assembly == null)
458467
{
459-
throw new Exception("");
468+
throw new Exception(ExceptionMessage.BatchOperations_AssemblyNotFound);
460469
}
461470

462-
var type = assembly.GetType("Microsoft.Data.Entity.SqlServerMetadataExtensions");
471+
var type = assembly.GetType("Microsoft.EntityFrameworkCore.SqlServerMetadataExtensions");
463472
var sqlServerPropertyMethod = type.GetMethod("SqlServer", new[] {typeof (IProperty)});
464473
#else
465474
var assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.FullName.StartsWith("Microsoft.EntityFrameworkCore.SqlServer"));
466475

467476
if (assembly == null)
468477
{
469-
throw new Exception("");
478+
throw new Exception(ExceptionMessage.BatchOperations_AssemblyNotFound);
470479
}
471480

472481
var type = assembly.GetType("Microsoft.EntityFrameworkCore.SqlServerMetadataExtensions");

src/Z.EntityFramework.Plus.EF6/ExceptionMessage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ internal class ExceptionMessage
1616
#endif
1717
#if FULL || BATCH_DELETE || BATCH_UPDATE
1818
public static string BatchOperations_PropertyNotFound = "Oops! Mapping for the property '{0}' cannot be found, the current version don't support yet Complex Type, Enum, TPC, TPH and TPT. For more information, contact us: [email protected]";
19+
public static string BatchOperations_AssemblyNotFound = "Oops! The assembly 'Microsoft.EntityFrameworkCore.SqlServer' could not be found. This feature is only supported for SQL Server for .NET Core. For more information, contact us: [email protected]";
1920
#endif
2021
#if FULL || QUERY_INCLUDEFILTER
2122
public static string QueryIncludeFilter_ArgumentExpression = "Oops! immediate method with expression argument are not supported in EF+ Query IncludeFilter. For more information, contact us: [email protected]";

src/Z.EntityFramework.Plus.EFCore/BatchDelete/BatchDelete.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,20 @@ public DbCommand CreateCommand(IQueryable query, IEntityType entity)
309309
#if NETSTANDARD1_3
310310
try
311311
{
312-
var assembly = Assembly.Load(new AssemblyName("EntityFramework.MicrosoftSqlServer, Version = 7.0.0.0, Culture = neutral, PublicKeyToken = adb9793829ddae60"));
312+
Assembly assembly;
313+
314+
try
315+
{
316+
assembly = Assembly.Load(new AssemblyName("Microsoft.EntityFrameworkCore.SqlServer"));
317+
}
318+
catch (Exception ex)
319+
{
320+
throw new Exception(ExceptionMessage.BatchOperations_AssemblyNotFound);
321+
}
313322

314323
if (assembly != null)
315324
{
316-
var type = assembly.GetType("Microsoft.Data.Entity.SqlServerMetadataExtensions");
325+
var type = assembly.GetType("Microsoft.EntityFrameworkCore.SqlServerMetadataExtensions");
317326

318327
var sqlServerEntityTypeMethod = type.GetMethod("SqlServer", new[] {typeof (IEntityType)});
319328
var sqlServerPropertyMethod = type.GetMethod("SqlServer", new[] {typeof (IProperty)});

src/Z.EntityFramework.Plus.EFCore/BatchUpdate/BatchUpdate.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,20 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
302302
public DbCommand CreateCommand(IQueryable query, IEntityType entity, List<Tuple<string, object>> values)
303303
{
304304
#if NETSTANDARD1_3
305-
var assembly = Assembly.Load(new AssemblyName("EntityFramework.MicrosoftSqlServer, Version = 7.0.0.0, Culture = neutral, PublicKeyToken = adb9793829ddae60"));
305+
Assembly assembly;
306+
307+
try
308+
{
309+
assembly = Assembly.Load(new AssemblyName("Microsoft.EntityFrameworkCore.SqlServer"));
310+
}
311+
catch (Exception ex)
312+
{
313+
throw new Exception(ExceptionMessage.BatchOperations_AssemblyNotFound);
314+
}
306315

307316
if (assembly != null)
308317
{
309-
var type = assembly.GetType("Microsoft.Data.Entity.SqlServerMetadataExtensions");
318+
var type = assembly.GetType("Microsoft.EntityFrameworkCore.SqlServerMetadataExtensions");
310319
var sqlServerEntityTypeMethod = type.GetMethod("SqlServer", new[] {typeof (IEntityType)});
311320
var sqlServerPropertyMethod = type.GetMethod("SqlServer", new[] {typeof (IProperty)});
312321
var sqlServer = (IRelationalEntityTypeAnnotations) sqlServerEntityTypeMethod.Invoke(null, new[] {entity});
@@ -447,26 +456,26 @@ public List<Tuple<string, object>> GetInnerValues<T>(IQueryable<T> query, Expres
447456

448457
try
449458
{
450-
assembly = Assembly.Load(new AssemblyName("EntityFramework.MicrosoftSqlServer, Version = 7.0.0.0, Culture = neutral, PublicKeyToken = adb9793829ddae60"));
459+
assembly = Assembly.Load(new AssemblyName("Microsoft.EntityFrameworkCore.SqlServer"));
451460
}
452-
catch (Exception)
461+
catch (Exception ex)
453462
{
454-
throw new Exception("");
463+
throw new Exception(ExceptionMessage.BatchOperations_AssemblyNotFound);
455464
}
456465

457466
if (assembly == null)
458467
{
459-
throw new Exception("");
468+
throw new Exception(ExceptionMessage.BatchOperations_AssemblyNotFound);
460469
}
461470

462-
var type = assembly.GetType("Microsoft.Data.Entity.SqlServerMetadataExtensions");
471+
var type = assembly.GetType("Microsoft.EntityFrameworkCore.SqlServerMetadataExtensions");
463472
var sqlServerPropertyMethod = type.GetMethod("SqlServer", new[] {typeof (IProperty)});
464473
#else
465474
var assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.FullName.StartsWith("Microsoft.EntityFrameworkCore.SqlServer"));
466475

467476
if (assembly == null)
468477
{
469-
throw new Exception("");
478+
throw new Exception(ExceptionMessage.BatchOperations_AssemblyNotFound);
470479
}
471480

472481
var type = assembly.GetType("Microsoft.EntityFrameworkCore.SqlServerMetadataExtensions");

src/Z.EntityFramework.Plus.EFCore/ExceptionMessage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ internal class ExceptionMessage
1616
#endif
1717
#if FULL || BATCH_DELETE || BATCH_UPDATE
1818
public static string BatchOperations_PropertyNotFound = "Oops! Mapping for the property '{0}' cannot be found, the current version don't support yet Complex Type, Enum, TPC, TPH and TPT. For more information, contact us: [email protected]";
19+
public static string BatchOperations_AssemblyNotFound = "Oops! The assembly 'Microsoft.EntityFrameworkCore.SqlServer' could not be found. This feature is only supported for SQL Server for .NET Core. For more information, contact us: [email protected]";
1920
#endif
2021
#if FULL || QUERY_INCLUDEFILTER
2122
public static string QueryIncludeFilter_ArgumentExpression = "Oops! immediate method with expression argument are not supported in EF+ Query IncludeFilter. For more information, contact us: [email protected]";

src/Z.EntityFramework.Plus.EFCore/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
[assembly: AssemblyCulture("")]
1919
[assembly: ComVisible(false)]
2020
[assembly: Guid("c41195f5-937e-4f2b-9f36-20650a804caa")]
21-
[assembly: AssemblyVersion("1.3.5")]
22-
[assembly: AssemblyFileVersion("1.3.5")]
21+
[assembly: AssemblyVersion("1.3.7")]
22+
[assembly: AssemblyFileVersion("1.3.7")]

src/Z.EntityFramework.Plus.EFCore/_Internal/Model/Model/Model.GetModelName.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ internal static partial class Model
2020
/// <returns>The model name.</returns>
2121
internal static string GetModelName(this DbContext @this)
2222
{
23-
var connectionString = @this.Database.Connection.ConnectionString;
23+
// Only EntityConnection contains model
24+
var connectionString = @this.Database.GetEntityConnection().ConnectionString;
2425
var end = connectionString.IndexOf(".msl") - 1;
2526

2627
if (end <= -1)

src/Z.EntityFramework.Plus.EFCore/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.3.5",
2+
"version": "1.3.7",
33
"description": "Description: EF Bulk Operations & Utilities | Bulk Insert, Update, Delete, Merge from database.",
44
"authors": [ "ZZZ Projects Inc." ],
55
"packOptions": {

0 commit comments

Comments
 (0)