|
@@ -114,9 +114,9 @@ namespace Luticate2.Utils.DataAccess
|
114
|
114
|
|
115
|
115
|
|
116
|
116
|
|
117
|
|
- protected virtual LuResult<TModel> _Add(TDboCreate dbo, TDbContext db, DbSet<TModel> table)
|
|
117
|
+ protected virtual LuResult<bool> _Add(TModel model, TDboCreate dbo, TDbContext db, DbSet<TModel> table)
|
118
|
118
|
{
|
119
|
|
- return LuResult<TModel>.Ok(GetModelFromTCreate(dbo));
|
|
119
|
+ return LuResult<bool>.Ok(true);
|
120
|
120
|
}
|
121
|
121
|
|
122
|
122
|
public virtual LuResult<T> Add<T>(IEnumerable<TDboCreate> objs, Func<IEnumerable<TDboRead>, T> returnFunc)
|
|
@@ -127,20 +127,17 @@ namespace Luticate2.Utils.DataAccess
|
127
|
127
|
var transact = BeginTransaction(db);
|
128
|
128
|
foreach (var dbo in objs)
|
129
|
129
|
{
|
130
|
|
- var res = _Add(dbo, db, table);
|
|
130
|
+ var model = GetModelFromTCreate(dbo);
|
|
131
|
+ table.Add(model);
|
|
132
|
+ models.Add(model);
|
|
133
|
+ var res = _Add(model, dbo, db, table);
|
131
|
134
|
if (!res)
|
132
|
135
|
{
|
133
|
136
|
RollbackTransaction(transact);
|
134
|
137
|
return res.To<T>();
|
135
|
138
|
}
|
136
|
|
- table.Add(res.Data);
|
137
|
|
- models.Add(res.Data);
|
138
|
139
|
}
|
139
|
140
|
db.SaveChanges();
|
140
|
|
- foreach (var model in models)
|
141
|
|
- {
|
142
|
|
- db.Entry(model).State = EntityState.Detached;
|
143
|
|
- }
|
144
|
141
|
CommitTransaction(transact);
|
145
|
142
|
return LuResult<T>.Ok(default(T));
|
146
|
143
|
});
|
|
@@ -186,7 +183,7 @@ namespace Luticate2.Utils.DataAccess
|
186
|
183
|
{
|
187
|
184
|
return Execute((db, table) =>
|
188
|
185
|
{
|
189
|
|
- var model = GetGetQueryable(db, table).AsNoTracking().FirstOrDefault(predicate);
|
|
186
|
+ var model = GetGetQueryable(db, table).FirstOrDefault(predicate);
|
190
|
187
|
if (model == default(TModel))
|
191
|
188
|
{
|
192
|
189
|
return GetNotFoundResult<TDboRead>();
|
|
@@ -240,7 +237,7 @@ namespace Luticate2.Utils.DataAccess
|
240
|
237
|
{
|
241
|
238
|
ordered = func(ordered);
|
242
|
239
|
}
|
243
|
|
- var data = ordered.Where(predicate).Skip(page * perPage).Take(perPage).AsNoTracking().Select(GetDboFromModel).ToList();
|
|
240
|
+ var data = ordered.Where(predicate).Skip(page * perPage).Take(perPage).Select(GetDboFromModel).ToList();
|
244
|
241
|
var result = new LuPaginatedDbo<TDboRead>
|
245
|
242
|
{
|
246
|
243
|
Count = count,
|
|
@@ -285,7 +282,7 @@ namespace Luticate2.Utils.DataAccess
|
285
|
282
|
if (exp == null)
|
286
|
283
|
{
|
287
|
284
|
return LuResult<LuPaginatedDbo<TDboRead>>.Error(LuStatus.InputError,
|
288
|
|
- string.Format("LuEfCrudDataAccess: {0}", field.Name), "Invalid order by field");
|
|
285
|
+ $"LuEfCrudDataAccess: {field.Name}", "Invalid order by field");
|
289
|
286
|
}
|
290
|
287
|
if (ordered != null)
|
291
|
288
|
{
|
|
@@ -297,7 +294,7 @@ namespace Luticate2.Utils.DataAccess
|
297
|
294
|
}
|
298
|
295
|
}
|
299
|
296
|
|
300
|
|
- var data = ordered.Skip(page * perPage).Take(perPage).AsNoTracking().Select(GetDboFromModel).ToList();
|
|
297
|
+ var data = ordered.Skip(page * perPage).Take(perPage).Select(GetDboFromModel).ToList();
|
301
|
298
|
var result = new LuPaginatedDbo<TDboRead>
|
302
|
299
|
{
|
303
|
300
|
Count = count,
|
|
@@ -327,11 +324,10 @@ namespace Luticate2.Utils.DataAccess
|
327
|
324
|
// IList<TModel> models = null;
|
328
|
325
|
// var editRes = Execute((db, table) =>
|
329
|
326
|
// {
|
330
|
|
-// models = GetEditQueryable(db, table).Where(predicate).AsNoTracking().ToList();
|
|
327
|
+// models = GetEditQueryable(db, table).Where(predicate).ToList();
|
331
|
328
|
// foreach (var model in models)
|
332
|
329
|
// {
|
333
|
330
|
// update(model);
|
334
|
|
-// db.Entry(model).State = EntityState.Modified;
|
335
|
331
|
// }
|
336
|
332
|
// db.SaveChanges();
|
337
|
333
|
// return LuResult<T>.Ok(default(T));
|
|
@@ -376,9 +372,8 @@ namespace Luticate2.Utils.DataAccess
|
376
|
372
|
// return EditSingleById(id, update, read => read);
|
377
|
373
|
// }
|
378
|
374
|
|
379
|
|
- protected virtual LuResult<bool> _EditSingleById(TId id, TModel model, TDboUpdate update, TDbContext db, DbSet<TModel> table)
|
|
375
|
+ protected virtual LuResult<bool> _EditSingleById(TModel model, TDboUpdate update, TDbContext db, DbSet<TModel> table)
|
380
|
376
|
{
|
381
|
|
- EditModelFromTUpdate(update, model);
|
382
|
377
|
return LuResult<bool>.Ok(true);
|
383
|
378
|
}
|
384
|
379
|
|
|
@@ -393,13 +388,14 @@ namespace Luticate2.Utils.DataAccess
|
393
|
388
|
var editRes = Execute((db, table) =>
|
394
|
389
|
{
|
395
|
390
|
var model = GetEditQueryable(db, table).FirstOrDefault(GetExpression(new KeyValuePair<string, object>("id", guid)));
|
396
|
|
- var res = _EditSingleById(id, model, update, db, table);
|
|
391
|
+ EditModelFromTUpdate(update, model);
|
|
392
|
+ db.SaveChanges();
|
|
393
|
+ var res = _EditSingleById(model, update, db, table);
|
397
|
394
|
if (!res)
|
398
|
395
|
{
|
399
|
396
|
RollbackTransaction(transact);
|
400
|
397
|
return res.To<T>();
|
401
|
398
|
}
|
402
|
|
- db.Entry(model).State = EntityState.Modified;
|
403
|
399
|
db.SaveChanges();
|
404
|
400
|
return LuResult<T>.Ok(default(T));
|
405
|
401
|
});
|
|
@@ -432,7 +428,7 @@ namespace Luticate2.Utils.DataAccess
|
432
|
428
|
return Execute((db, table) =>
|
433
|
429
|
{
|
434
|
430
|
var transact = BeginTransaction(db);
|
435
|
|
- var models = GetDeleteQueryable(db, table).Where(predicate).AsNoTracking().ToList();
|
|
431
|
+ var models = GetDeleteQueryable(db, table).Where(predicate).ToList();
|
436
|
432
|
var getRes = GetMultiple(models, returnFunc);
|
437
|
433
|
if (!getRes)
|
438
|
434
|
{
|