Skip to content

Commit

Permalink
0.9.6.0—Fixed multiple contexts referencing entity bug
Browse files Browse the repository at this point in the history
  • Loading branch information
piranout committed May 6, 2016
1 parent 98bb12c commit f9c9036
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 26 deletions.
33 changes: 11 additions & 22 deletions EntityFramework/ConcurrentEntityFrameworkProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected ConcurrentEntityFrameworkProvider()
public Action<string> Log { get {return _log;} set { _log = value; } }

/// <summary>
/// Get an entity by its Id
/// Gets an entity by its Id.
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TKey"></typeparam>
Expand Down Expand Up @@ -157,10 +157,7 @@ public override IEnumerable<TEntity> Insert<TEntity, TId>(ICollection<TEntity> e
{
using(var context = GetNewContext(_connectionString))
{
foreach (var entity in entities)
{
context.Set<TEntity>().Add(entity);
}
context.Set<TEntity>().AddRange(entities);
if (safe)
context.SaveChanges();
else
Expand All @@ -182,15 +179,14 @@ public override IEnumerable<TEntity> Insert<TEntity, TId>(ICollection<TEntity> e
/// <returns></returns>
public override TEntity Insert<TEntity, TId>(TEntity entity, bool safe = true)
{
var createable = entity as ICreateable<TId>;
/*var createable = entity as ICreateable<TId>;
if(createable != null)
SetCreateableProperties<TId>(createable);
SetCreateableProperties<TId>(createable);*/
using (var context = GetContext())
{
context.Configuration.AutoDetectChangesEnabled = true;
//context.Configuration.AutoDetectChangesEnabled = true;
context.Set<TEntity>().Add(entity);
SetCreatableModifyableProperties<TId>(context);
//context.Entry(entity).State = EntityState.Added;//// context.Set<TEntity>().Add(entity);
if (safe)
context.SaveChanges();
else
Expand All @@ -212,21 +208,19 @@ public override TEntity Insert<TEntity, TId>(TEntity entity, bool safe = true)
/// <returns></returns>
public override IEnumerable<TEntity> Update<TEntity, TId>(ICollection<TEntity> entities, bool safe = true)
{
var entityArray = SetModifyableProperties<TEntity, TId>(entities).ToArray();
using (var context = GetContext())
{
foreach (var entity in entityArray)
foreach (var entity in entities)
{
context.AttachAndModify(entity);
var dbEntityEntry = this.Context.Entry(entity);
dbEntityEntry.State = EntityState.Modified;
context.Entry(entity).State = EntityState.Modified;
}
SetCreatableModifyableProperties<TId>(context);
if (safe)
context.SaveChanges();
else
context.SaveChangesAsync();
}
return entityArray;
return entities;
}

/// <summary>
Expand All @@ -242,14 +236,10 @@ public override IEnumerable<TEntity> Update<TEntity, TId>(ICollection<TEntity> e
/// <returns></returns>
public override TEntity Update<TEntity, TId>(TEntity entity, bool safe = true)
{
SetModifyableProperties<TId>(entity as IModifyable<TId>);
using (var context = GetContext())
{

context.Entry(entity).State = EntityState.Modified;
/*var dbEntityEntry = this.Context.Entry(entity);
dbEntityEntry.State = EntityState.Modified;*/

SetCreatableModifyableProperties<TId>(context);
if (safe)
context.SaveChanges();
else
Expand All @@ -272,7 +262,6 @@ public override IEnumerable<TEntity> BulkInsert<TEntity, TId>(ICollection<TEntit
{
context.Set<TEntity>().AddRange(entities);
SetCreatableModifyableProperties<TId>(context);
// SetCreatableProperties<TEntity, TId>(entities).ToArray();
}
using (var context = GetContext())
{
Expand Down Expand Up @@ -307,7 +296,7 @@ public override void BulkUpdate<TEntity, TProp>(Expression<Func<TEntity, bool>>
}

/// <summary>
/// Delete an entity.
/// Delete an entity for which you have the instance.
/// </summary>
/// <param name="entity"></param>
public override void Delete<TEntity, TId>(TEntity entity)
Expand Down
1 change: 1 addition & 0 deletions Funcular.DataProviders.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<None Include="NuGet\Funcular.DataProviders.0.6.1.0.nupkg" />
<None Include="NuGet\Funcular.DataProviders.0.8.5.0.nupkg" />
<None Include="NuGet\Funcular.DataProviders.0.9.5.0.nupkg" />
<None Include="NuGet\Funcular.DataProviders.0.9.6.0.nupkg" />
<None Include="packages.config" />
<None Include="README.md" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions IntegrationTests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.5.0")]
[assembly: AssemblyFileVersion("0.9.5.0")]
[assembly: AssemblyVersion("0.9.6.0")]
[assembly: AssemblyFileVersion("0.9.6.0")]
Binary file added NuGet/Funcular.DataProviders.0.9.6.0.nupkg
Binary file not shown.
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("0.9.5.0")]
[assembly: AssemblyFileVersion("0.9.5.0")]
[assembly: AssemblyVersion("0.9.6.0")]
[assembly: AssemblyFileVersion("0.9.6.0")]

0 comments on commit f9c9036

Please sign in to comment.