@@ -76,7 +76,7 @@ protected ConcurrentEntityFrameworkProvider()
76
76
public Action < string > Log { get { return _log ; } set { _log = value ; } }
77
77
78
78
/// <summary>
79
- /// Get an entity by its Id
79
+ /// Gets an entity by its Id.
80
80
/// </summary>
81
81
/// <typeparam name="TEntity"></typeparam>
82
82
/// <typeparam name="TKey"></typeparam>
@@ -157,10 +157,7 @@ public override IEnumerable<TEntity> Insert<TEntity, TId>(ICollection<TEntity> e
157
157
{
158
158
using ( var context = GetNewContext ( _connectionString ) )
159
159
{
160
- foreach ( var entity in entities )
161
- {
162
- context . Set < TEntity > ( ) . Add ( entity ) ;
163
- }
160
+ context . Set < TEntity > ( ) . AddRange ( entities ) ;
164
161
if ( safe )
165
162
context . SaveChanges ( ) ;
166
163
else
@@ -182,15 +179,14 @@ public override IEnumerable<TEntity> Insert<TEntity, TId>(ICollection<TEntity> e
182
179
/// <returns></returns>
183
180
public override TEntity Insert < TEntity , TId > ( TEntity entity , bool safe = true )
184
181
{
185
- var createable = entity as ICreateable < TId > ;
182
+ /* var createable = entity as ICreateable<TId>;
186
183
if(createable != null)
187
- SetCreateableProperties < TId > ( createable ) ;
184
+ SetCreateableProperties<TId>(createable);*/
188
185
using ( var context = GetContext ( ) )
189
186
{
190
- context . Configuration . AutoDetectChangesEnabled = true ;
187
+ // context.Configuration.AutoDetectChangesEnabled = true;
191
188
context . Set < TEntity > ( ) . Add ( entity ) ;
192
189
SetCreatableModifyableProperties < TId > ( context ) ;
193
- //context.Entry(entity).State = EntityState.Added;//// context.Set<TEntity>().Add(entity);
194
190
if ( safe )
195
191
context . SaveChanges ( ) ;
196
192
else
@@ -212,21 +208,19 @@ public override TEntity Insert<TEntity, TId>(TEntity entity, bool safe = true)
212
208
/// <returns></returns>
213
209
public override IEnumerable < TEntity > Update < TEntity , TId > ( ICollection < TEntity > entities , bool safe = true )
214
210
{
215
- var entityArray = SetModifyableProperties < TEntity , TId > ( entities ) . ToArray ( ) ;
216
211
using ( var context = GetContext ( ) )
217
212
{
218
- foreach ( var entity in entityArray )
213
+ foreach ( var entity in entities )
219
214
{
220
- context . AttachAndModify ( entity ) ;
221
- var dbEntityEntry = this . Context . Entry ( entity ) ;
222
- dbEntityEntry . State = EntityState . Modified ;
215
+ context . Entry ( entity ) . State = EntityState . Modified ;
223
216
}
217
+ SetCreatableModifyableProperties < TId > ( context ) ;
224
218
if ( safe )
225
219
context . SaveChanges ( ) ;
226
220
else
227
221
context . SaveChangesAsync ( ) ;
228
222
}
229
- return entityArray ;
223
+ return entities ;
230
224
}
231
225
232
226
/// <summary>
@@ -242,14 +236,10 @@ public override IEnumerable<TEntity> Update<TEntity, TId>(ICollection<TEntity> e
242
236
/// <returns></returns>
243
237
public override TEntity Update < TEntity , TId > ( TEntity entity , bool safe = true )
244
238
{
245
- SetModifyableProperties < TId > ( entity as IModifyable < TId > ) ;
246
239
using ( var context = GetContext ( ) )
247
240
{
248
-
249
241
context . Entry ( entity ) . State = EntityState . Modified ;
250
- /*var dbEntityEntry = this.Context.Entry(entity);
251
- dbEntityEntry.State = EntityState.Modified;*/
252
-
242
+ SetCreatableModifyableProperties < TId > ( context ) ;
253
243
if ( safe )
254
244
context . SaveChanges ( ) ;
255
245
else
@@ -272,7 +262,6 @@ public override IEnumerable<TEntity> BulkInsert<TEntity, TId>(ICollection<TEntit
272
262
{
273
263
context . Set < TEntity > ( ) . AddRange ( entities ) ;
274
264
SetCreatableModifyableProperties < TId > ( context ) ;
275
- // SetCreatableProperties<TEntity, TId>(entities).ToArray();
276
265
}
277
266
using ( var context = GetContext ( ) )
278
267
{
@@ -307,7 +296,7 @@ public override void BulkUpdate<TEntity, TProp>(Expression<Func<TEntity, bool>>
307
296
}
308
297
309
298
/// <summary>
310
- /// Delete an entity.
299
+ /// Delete an entity for which you have the instance .
311
300
/// </summary>
312
301
/// <param name="entity"></param>
313
302
public override void Delete < TEntity , TId > ( TEntity entity )
0 commit comments