Browse Source

removed EF cache

tags/v0.1.6
Robin Thoni 8 years ago
parent
commit
781149df84
1 changed files with 9 additions and 5 deletions
  1. 9
    5
      Luticate2.Utils/DataAccess/LuEfCrudDataAccess.cs

+ 9
- 5
Luticate2.Utils/DataAccess/LuEfCrudDataAccess.cs View File

112
                 var models = objs.Select(GetModelFromTCreate).ToList();
112
                 var models = objs.Select(GetModelFromTCreate).ToList();
113
                 Table.AddRange(models);
113
                 Table.AddRange(models);
114
                 Db.SaveChanges();
114
                 Db.SaveChanges();
115
+                foreach (var model in models)
116
+                {
117
+                    Db.Entry(model).State = EntityState.Detached;
118
+                }
115
                 var dbos = models.Select(GetDboFromModel).ToList();
119
                 var dbos = models.Select(GetDboFromModel).ToList();
116
                 var res = returnFunc(dbos);
120
                 var res = returnFunc(dbos);
117
                 return LuResult<T>.Ok(res);
121
                 return LuResult<T>.Ok(res);
153
         {
157
         {
154
             return Execute(() =>
158
             return Execute(() =>
155
             {
159
             {
156
-                var model = GetGetQueryable().FirstOrDefault(predicate);
160
+                var model = GetGetQueryable().AsNoTracking().FirstOrDefault(predicate);
157
                 if (model == default(TModel))
161
                 if (model == default(TModel))
158
                 {
162
                 {
159
                     return GetNotFoundResult<TDboRead>();
163
                     return GetNotFoundResult<TDboRead>();
192
                 {
196
                 {
193
                     ordered = func(ordered);
197
                     ordered = func(ordered);
194
                 }
198
                 }
195
-                var data = ordered.Where(predicate).Skip(page * perPage).Take(perPage).Select(GetDboFromModel).ToList();
199
+                var data = ordered.Where(predicate).Skip(page * perPage).Take(perPage).AsNoTracking().Select(GetDboFromModel).ToList();
196
                 var result = new LuPaginatedDbo<TDboRead>
200
                 var result = new LuPaginatedDbo<TDboRead>
197
                 {
201
                 {
198
                     Count = count,
202
                     Count = count,
248
                     }
252
                     }
249
                 }
253
                 }
250
 
254
 
251
-                var data = ordered.Skip(page * perPage).Take(perPage).Select(GetDboFromModel).ToList();
255
+                var data = ordered.Skip(page * perPage).Take(perPage).AsNoTracking().Select(GetDboFromModel).ToList();
252
                 var result = new LuPaginatedDbo<TDboRead>
256
                 var result = new LuPaginatedDbo<TDboRead>
253
                 {
257
                 {
254
                     Count = count,
258
                     Count = count,
276
         {
280
         {
277
             return Execute(() =>
281
             return Execute(() =>
278
             {
282
             {
279
-                var models = GetEditQueryable().Where(predicate);
283
+                var models = GetEditQueryable().Where(predicate).AsNoTracking();
280
                 var editedDbos = new List<TDboRead>();
284
                 var editedDbos = new List<TDboRead>();
281
                 foreach (var model in models)
285
                 foreach (var model in models)
282
                 {
286
                 {
353
         {
357
         {
354
             return Execute(() =>
358
             return Execute(() =>
355
             {
359
             {
356
-                var models = GetDeleteQueryable().Where(predicate).ToList();
360
+                var models = GetDeleteQueryable().Where(predicate).AsNoTracking().ToList();
357
                 Table.RemoveRange(models);
361
                 Table.RemoveRange(models);
358
                 Db.SaveChanges();
362
                 Db.SaveChanges();
359
                 var dbos = models.Select(GetDboFromModel);
363
                 var dbos = models.Select(GetDboFromModel);

Loading…
Cancel
Save