Skip to content

Commit

Permalink
Fix BatchUpdate, BatchDelete Issue with Database First
Browse files Browse the repository at this point in the history
Fix BatchUpdate, BatchDelete Issue with Database First
  • Loading branch information
zzzprojects committed Jun 17, 2016
1 parent 06e52f7 commit f29d283
Show file tree
Hide file tree
Showing 35 changed files with 222 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("e4c2af73-caeb-4429-bcb6-0a359484e064")]
[assembly: AssemblyVersion("1.2.1")]
[assembly: AssemblyFileVersion("1.2.1")]
[assembly: AssemblyVersion("1.2.4")]
[assembly: AssemblyFileVersion("1.2.4")]
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<Compile Include="_Internal\EF5\DbContext.SaveChangesAsync.cs" />
<Compile Include="_Internal\EF5\IDbSet`\DbContext.AddRange.cs" />
<Compile Include="_Internal\EF5\IDbSet`\DbContext.RemoveRange.cs" />
<Compile Include="_Internal\EF5_EF6\Database\GetEntityConnection.cs" />
<Compile Include="_Internal\EF5_EF6\DbContext\DbContext.GetObjectContext.cs" />
<Compile Include="_Internal\EF5_EF6\EntityConnection\GetDbTransaction.cs" />
<Compile Include="_Internal\EF5_EF6\EntityConnection\GetEntityTransaction.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static class DynamicAnonymousType
{

private static readonly AssemblyName AssemblyName = new AssemblyName { Name = "<>f__AnonymousType" };
#if NETCORE50
#if NETSTANDARD1_3
private static readonly ModuleBuilder ModuleBuilder = System.Reflection.Emit.AssemblyBuilder.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.Run).DefineDynamicModule(AssemblyName.Name);
#else
private static readonly ModuleBuilder ModuleBuilder = Thread.GetDomain().DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.Run).DefineDynamicModule(AssemblyName.Name);
Expand Down Expand Up @@ -112,7 +112,7 @@ public static Type GetDynamicType(List<Tuple<string, Type>> fields)
foreach (var field in fields)
typeBuilder.DefineField(field.Item1, field.Item2, FieldAttributes.Public);

#if NETCORE50
#if NETSTANDARD1_3
BuiltTypes[typeKey] = new Tuple<string, Type>(typeName, typeBuilder.CreateTypeInfo().AsType());
#else
BuiltTypes[typeKey] = new Tuple<string, Type>(typeName, typeBuilder.CreateType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal static List<PropertyInfo> GetDbSetProperties(this DbContext context)
#if EF5 || EF6
var isDbSet = setType.IsGenericType && (typeof (IDbSet<>).IsAssignableFrom(setType.GetGenericTypeDefinition()) || setType.GetInterface(typeof (IDbSet<>).FullName) != null);
#elif EFCORE
#if NETCORE50
#if NETSTANDARD1_3
var isDbSet = setType.GetType().IsConstructedGenericType && (typeof (DbSet<>).IsAssignableFrom(setType.GetGenericTypeDefinition()));
#else
var isDbSet = setType.IsGenericType && (typeof(DbSet<>).IsAssignableFrom(setType.GetGenericTypeDefinition()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if FULL
using System.Linq;
using System.Linq.Expressions;
#if NETCORE50
#if NETSTANDARD1_3
using System.Reflection;
#endif
namespace Z.EntityFramework.Plus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static Type GetDbSetElementType(this Type type)
return null;
#elif EFCORE

#if NETCORE50
#if NETSTANDARD1_3
return type.GetTypeInfo().GenericTypeArguments[0];
#else
return type.GetGenericArguments()[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Description: Entity Framework Bulk Operations & Utilities (EF Bulk SaveChanges, Insert, Update, Delete, Merge | LINQ Query Cache, Deferred, Filter, IncludeFilter, IncludeOptimize | Audit)
// Website & Documentation: https://github.com/zzzprojects/Entity-Framework-Plus
// Forum & Issues: https://github.com/zzzprojects/EntityFramework-Plus/issues
// License: https://github.com/zzzprojects/EntityFramework-Plus/blob/master/LICENSE
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.

#if FULL || BATCHDELETE || BATCHUPDATE
#if EF5 || EF6

#if EF5
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.EntityClient;
using System.Data.Objects;
using System.Reflection;

#elif EF6
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Core.Objects;
using System.Reflection;

#endif

namespace Z.EntityFramework.Plus
{
internal static partial class InternalExtensions
{
public static EntityConnection GetEntityConnection(this Database @this)
{
object internalContext = @this.GetType().GetField("_internalContext", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(@this);

MethodInfo getObjectContext = internalContext.GetType().GetMethod("GetObjectContextWithoutDatabaseInitialization", BindingFlags.Public | BindingFlags.Instance);
var objectContext = (ObjectContext)getObjectContext.Invoke(internalContext, null);
DbConnection entityConnection = objectContext.Connection;

return (EntityConnection)entityConnection;
}
}
}

#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using System.Linq;
using System.Linq.Expressions;

#if NETCORE50
#if NETSTANDARD1_3
using System.Reflection;
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override int RecordsAffected
get { return OriginalDataReader.RecordsAffected; }
}

//#if !NETCORE50
//#if !NETSTANDARD1_3
// public override void Close()
// {
// // DO NOT close reader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static partial class Model
/// <returns>The model name.</returns>
internal static string GetModelName(this DbContext @this)
{
var connectionString = @this.Database.Connection.ConnectionString;
var connectionString = @this.Database.GetEntityConnection().ConnectionString;
var end = connectionString.IndexOf(".msl") - 1;

if (end <= -1)
Expand Down
4 changes: 2 additions & 2 deletions src/Z.EntityFramework.Plus.EF5/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("abcbb878-043c-4957-a334-90e9872e684e")]
[assembly: AssemblyVersion("1.2.1")]
[assembly: AssemblyFileVersion("1.2.1")]
[assembly: AssemblyVersion("1.2.4")]
[assembly: AssemblyFileVersion("1.2.4")]
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<Compile Include="_Internal\EF5\DbContext.SaveChangesAsync.cs" />
<Compile Include="_Internal\EF5\IDbSet`\DbContext.AddRange.cs" />
<Compile Include="_Internal\EF5\IDbSet`\DbContext.RemoveRange.cs" />
<Compile Include="_Internal\EF5_EF6\Database\GetEntityConnection.cs" />
<Compile Include="_Internal\EF5_EF6\DbContext\DbContext.GetObjectContext.cs" />
<Compile Include="_Internal\EF5_EF6\EntityConnection\GetDbTransaction.cs" />
<Compile Include="_Internal\EF5_EF6\EntityConnection\GetEntityTransaction.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static class DynamicAnonymousType
{

private static readonly AssemblyName AssemblyName = new AssemblyName { Name = "<>f__AnonymousType" };
#if NETCORE50
#if NETSTANDARD1_3
private static readonly ModuleBuilder ModuleBuilder = System.Reflection.Emit.AssemblyBuilder.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.Run).DefineDynamicModule(AssemblyName.Name);
#else
private static readonly ModuleBuilder ModuleBuilder = Thread.GetDomain().DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.Run).DefineDynamicModule(AssemblyName.Name);
Expand Down Expand Up @@ -112,7 +112,7 @@ public static Type GetDynamicType(List<Tuple<string, Type>> fields)
foreach (var field in fields)
typeBuilder.DefineField(field.Item1, field.Item2, FieldAttributes.Public);

#if NETCORE50
#if NETSTANDARD1_3
BuiltTypes[typeKey] = new Tuple<string, Type>(typeName, typeBuilder.CreateTypeInfo().AsType());
#else
BuiltTypes[typeKey] = new Tuple<string, Type>(typeName, typeBuilder.CreateType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal static List<PropertyInfo> GetDbSetProperties(this DbContext context)
#if EF5 || EF6
var isDbSet = setType.IsGenericType && (typeof (IDbSet<>).IsAssignableFrom(setType.GetGenericTypeDefinition()) || setType.GetInterface(typeof (IDbSet<>).FullName) != null);
#elif EFCORE
#if NETCORE50
#if NETSTANDARD1_3
var isDbSet = setType.GetType().IsConstructedGenericType && (typeof (DbSet<>).IsAssignableFrom(setType.GetGenericTypeDefinition()));
#else
var isDbSet = setType.IsGenericType && (typeof(DbSet<>).IsAssignableFrom(setType.GetGenericTypeDefinition()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if FULL
using System.Linq;
using System.Linq.Expressions;
#if NETCORE50
#if NETSTANDARD1_3
using System.Reflection;
#endif
namespace Z.EntityFramework.Plus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static Type GetDbSetElementType(this Type type)
return null;
#elif EFCORE

#if NETCORE50
#if NETSTANDARD1_3
return type.GetTypeInfo().GenericTypeArguments[0];
#else
return type.GetGenericArguments()[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Description: Entity Framework Bulk Operations & Utilities (EF Bulk SaveChanges, Insert, Update, Delete, Merge | LINQ Query Cache, Deferred, Filter, IncludeFilter, IncludeOptimize | Audit)
// Website & Documentation: https://github.com/zzzprojects/Entity-Framework-Plus
// Forum & Issues: https://github.com/zzzprojects/EntityFramework-Plus/issues
// License: https://github.com/zzzprojects/EntityFramework-Plus/blob/master/LICENSE
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.

#if FULL || BATCHDELETE || BATCHUPDATE
#if EF5 || EF6

#if EF5
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.EntityClient;
using System.Data.Objects;
using System.Reflection;

#elif EF6
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Core.Objects;
using System.Reflection;

#endif

namespace Z.EntityFramework.Plus
{
internal static partial class InternalExtensions
{
public static EntityConnection GetEntityConnection(this Database @this)
{
object internalContext = @this.GetType().GetField("_internalContext", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(@this);

MethodInfo getObjectContext = internalContext.GetType().GetMethod("GetObjectContextWithoutDatabaseInitialization", BindingFlags.Public | BindingFlags.Instance);
var objectContext = (ObjectContext)getObjectContext.Invoke(internalContext, null);
DbConnection entityConnection = objectContext.Connection;

return (EntityConnection)entityConnection;
}
}
}

#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using System.Linq;
using System.Linq.Expressions;

#if NETCORE50
#if NETSTANDARD1_3
using System.Reflection;
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override int RecordsAffected
get { return OriginalDataReader.RecordsAffected; }
}

//#if !NETCORE50
//#if !NETSTANDARD1_3
// public override void Close()
// {
// // DO NOT close reader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static partial class Model
/// <returns>The model name.</returns>
internal static string GetModelName(this DbContext @this)
{
var connectionString = @this.Database.Connection.ConnectionString;
var connectionString = @this.Database.GetEntityConnection().ConnectionString;
var end = connectionString.IndexOf(".msl") - 1;

if (end <= -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("ac398eb8-0a31-4d06-a804-84d10b6da96d")]
[assembly: AssemblyVersion("1.2.1")]
[assembly: AssemblyFileVersion("1.2.1")]
[assembly: AssemblyVersion("1.2.4")]
[assembly: AssemblyFileVersion("1.2.4")]
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<Compile Include="_Internal\EF5\DbContext.SaveChangesAsync.cs" />
<Compile Include="_Internal\EF5\IDbSet`\DbContext.AddRange.cs" />
<Compile Include="_Internal\EF5\IDbSet`\DbContext.RemoveRange.cs" />
<Compile Include="_Internal\EF5_EF6\Database\GetEntityConnection.cs" />
<Compile Include="_Internal\EF5_EF6\DbContext\DbContext.GetObjectContext.cs" />
<Compile Include="_Internal\EF5_EF6\EntityConnection\GetDbTransaction.cs" />
<Compile Include="_Internal\EF5_EF6\EntityConnection\GetEntityTransaction.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static class DynamicAnonymousType
{

private static readonly AssemblyName AssemblyName = new AssemblyName { Name = "<>f__AnonymousType" };
#if NETCORE50
#if NETSTANDARD1_3
private static readonly ModuleBuilder ModuleBuilder = System.Reflection.Emit.AssemblyBuilder.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.Run).DefineDynamicModule(AssemblyName.Name);
#else
private static readonly ModuleBuilder ModuleBuilder = Thread.GetDomain().DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.Run).DefineDynamicModule(AssemblyName.Name);
Expand Down Expand Up @@ -112,7 +112,7 @@ public static Type GetDynamicType(List<Tuple<string, Type>> fields)
foreach (var field in fields)
typeBuilder.DefineField(field.Item1, field.Item2, FieldAttributes.Public);

#if NETCORE50
#if NETSTANDARD1_3
BuiltTypes[typeKey] = new Tuple<string, Type>(typeName, typeBuilder.CreateTypeInfo().AsType());
#else
BuiltTypes[typeKey] = new Tuple<string, Type>(typeName, typeBuilder.CreateType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal static List<PropertyInfo> GetDbSetProperties(this DbContext context)
#if EF5 || EF6
var isDbSet = setType.IsGenericType && (typeof (IDbSet<>).IsAssignableFrom(setType.GetGenericTypeDefinition()) || setType.GetInterface(typeof (IDbSet<>).FullName) != null);
#elif EFCORE
#if NETCORE50
#if NETSTANDARD1_3
var isDbSet = setType.GetType().IsConstructedGenericType && (typeof (DbSet<>).IsAssignableFrom(setType.GetGenericTypeDefinition()));
#else
var isDbSet = setType.IsGenericType && (typeof(DbSet<>).IsAssignableFrom(setType.GetGenericTypeDefinition()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if FULL
using System.Linq;
using System.Linq.Expressions;
#if NETCORE50
#if NETSTANDARD1_3
using System.Reflection;
#endif
namespace Z.EntityFramework.Plus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static Type GetDbSetElementType(this Type type)
return null;
#elif EFCORE

#if NETCORE50
#if NETSTANDARD1_3
return type.GetTypeInfo().GenericTypeArguments[0];
#else
return type.GetGenericArguments()[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Description: Entity Framework Bulk Operations & Utilities (EF Bulk SaveChanges, Insert, Update, Delete, Merge | LINQ Query Cache, Deferred, Filter, IncludeFilter, IncludeOptimize | Audit)
// Website & Documentation: https://github.com/zzzprojects/Entity-Framework-Plus
// Forum & Issues: https://github.com/zzzprojects/EntityFramework-Plus/issues
// License: https://github.com/zzzprojects/EntityFramework-Plus/blob/master/LICENSE
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.

#if FULL || BATCHDELETE || BATCHUPDATE
#if EF5 || EF6

#if EF5
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.EntityClient;
using System.Data.Objects;
using System.Reflection;

#elif EF6
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Core.Objects;
using System.Reflection;

#endif

namespace Z.EntityFramework.Plus
{
internal static partial class InternalExtensions
{
public static EntityConnection GetEntityConnection(this Database @this)
{
object internalContext = @this.GetType().GetField("_internalContext", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(@this);

MethodInfo getObjectContext = internalContext.GetType().GetMethod("GetObjectContextWithoutDatabaseInitialization", BindingFlags.Public | BindingFlags.Instance);
var objectContext = (ObjectContext)getObjectContext.Invoke(internalContext, null);
DbConnection entityConnection = objectContext.Connection;

return (EntityConnection)entityConnection;
}
}
}

#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using System.Linq;
using System.Linq.Expressions;

#if NETCORE50
#if NETSTANDARD1_3
using System.Reflection;
#endif

Expand Down
Loading

0 comments on commit f29d283

Please sign in to comment.