Skip to content

Commit f9c9036

Browse files
committed
0.9.6.0—Fixed multiple contexts referencing entity bug
1 parent 98bb12c commit f9c9036

File tree

5 files changed

+16
-26
lines changed

5 files changed

+16
-26
lines changed

EntityFramework/ConcurrentEntityFrameworkProvider.cs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected ConcurrentEntityFrameworkProvider()
7676
public Action<string> Log { get {return _log;} set { _log = value; } }
7777

7878
/// <summary>
79-
/// Get an entity by its Id
79+
/// Gets an entity by its Id.
8080
/// </summary>
8181
/// <typeparam name="TEntity"></typeparam>
8282
/// <typeparam name="TKey"></typeparam>
@@ -157,10 +157,7 @@ public override IEnumerable<TEntity> Insert<TEntity, TId>(ICollection<TEntity> e
157157
{
158158
using(var context = GetNewContext(_connectionString))
159159
{
160-
foreach (var entity in entities)
161-
{
162-
context.Set<TEntity>().Add(entity);
163-
}
160+
context.Set<TEntity>().AddRange(entities);
164161
if (safe)
165162
context.SaveChanges();
166163
else
@@ -182,15 +179,14 @@ public override IEnumerable<TEntity> Insert<TEntity, TId>(ICollection<TEntity> e
182179
/// <returns></returns>
183180
public override TEntity Insert<TEntity, TId>(TEntity entity, bool safe = true)
184181
{
185-
var createable = entity as ICreateable<TId>;
182+
/*var createable = entity as ICreateable<TId>;
186183
if(createable != null)
187-
SetCreateableProperties<TId>(createable);
184+
SetCreateableProperties<TId>(createable);*/
188185
using (var context = GetContext())
189186
{
190-
context.Configuration.AutoDetectChangesEnabled = true;
187+
//context.Configuration.AutoDetectChangesEnabled = true;
191188
context.Set<TEntity>().Add(entity);
192189
SetCreatableModifyableProperties<TId>(context);
193-
//context.Entry(entity).State = EntityState.Added;//// context.Set<TEntity>().Add(entity);
194190
if (safe)
195191
context.SaveChanges();
196192
else
@@ -212,21 +208,19 @@ public override TEntity Insert<TEntity, TId>(TEntity entity, bool safe = true)
212208
/// <returns></returns>
213209
public override IEnumerable<TEntity> Update<TEntity, TId>(ICollection<TEntity> entities, bool safe = true)
214210
{
215-
var entityArray = SetModifyableProperties<TEntity, TId>(entities).ToArray();
216211
using (var context = GetContext())
217212
{
218-
foreach (var entity in entityArray)
213+
foreach (var entity in entities)
219214
{
220-
context.AttachAndModify(entity);
221-
var dbEntityEntry = this.Context.Entry(entity);
222-
dbEntityEntry.State = EntityState.Modified;
215+
context.Entry(entity).State = EntityState.Modified;
223216
}
217+
SetCreatableModifyableProperties<TId>(context);
224218
if (safe)
225219
context.SaveChanges();
226220
else
227221
context.SaveChangesAsync();
228222
}
229-
return entityArray;
223+
return entities;
230224
}
231225

232226
/// <summary>
@@ -242,14 +236,10 @@ public override IEnumerable<TEntity> Update<TEntity, TId>(ICollection<TEntity> e
242236
/// <returns></returns>
243237
public override TEntity Update<TEntity, TId>(TEntity entity, bool safe = true)
244238
{
245-
SetModifyableProperties<TId>(entity as IModifyable<TId>);
246239
using (var context = GetContext())
247240
{
248-
249241
context.Entry(entity).State = EntityState.Modified;
250-
/*var dbEntityEntry = this.Context.Entry(entity);
251-
dbEntityEntry.State = EntityState.Modified;*/
252-
242+
SetCreatableModifyableProperties<TId>(context);
253243
if (safe)
254244
context.SaveChanges();
255245
else
@@ -272,7 +262,6 @@ public override IEnumerable<TEntity> BulkInsert<TEntity, TId>(ICollection<TEntit
272262
{
273263
context.Set<TEntity>().AddRange(entities);
274264
SetCreatableModifyableProperties<TId>(context);
275-
// SetCreatableProperties<TEntity, TId>(entities).ToArray();
276265
}
277266
using (var context = GetContext())
278267
{
@@ -307,7 +296,7 @@ public override void BulkUpdate<TEntity, TProp>(Expression<Func<TEntity, bool>>
307296
}
308297

309298
/// <summary>
310-
/// Delete an entity.
299+
/// Delete an entity for which you have the instance.
311300
/// </summary>
312301
/// <param name="entity"></param>
313302
public override void Delete<TEntity, TId>(TEntity entity)

Funcular.DataProviders.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
<None Include="NuGet\Funcular.DataProviders.0.6.1.0.nupkg" />
107107
<None Include="NuGet\Funcular.DataProviders.0.8.5.0.nupkg" />
108108
<None Include="NuGet\Funcular.DataProviders.0.9.5.0.nupkg" />
109+
<None Include="NuGet\Funcular.DataProviders.0.9.6.0.nupkg" />
109110
<None Include="packages.config" />
110111
<None Include="README.md" />
111112
</ItemGroup>

IntegrationTests/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("0.9.5.0")]
35-
[assembly: AssemblyFileVersion("0.9.5.0")]
34+
[assembly: AssemblyVersion("0.9.6.0")]
35+
[assembly: AssemblyFileVersion("0.9.6.0")]
37.3 KB
Binary file not shown.

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@
7272
// by using the '*' as shown below:
7373
// [assembly: AssemblyVersion("1.0.*")]
7474

75-
[assembly: AssemblyVersion("0.9.5.0")]
76-
[assembly: AssemblyFileVersion("0.9.5.0")]
75+
[assembly: AssemblyVersion("0.9.6.0")]
76+
[assembly: AssemblyFileVersion("0.9.6.0")]

0 commit comments

Comments
 (0)