public async Task AddRangeAsync(IEnumerable <TAggregateRoot> aggregateRoot) { using (var ctx = new WbcContext()) { ctx.Set <TAggregateRoot>().AddRange(aggregateRoot); await ctx.SaveChangesAsync(); } }
// private static Lazy<Expression<Func<TAggregateRoot, bool>>> equalExpression = new Lazy<Expression<Func<TAggregateRoot, bool>>>(() => //{ // var arg = Expression.Parameter(typeof(TId), "id"); // var exp = Expression.Equal(arg, Expression.Constant(id, typeof(TId))); // var exp2 = Expression.Lambda<Func<TAggregateRoot, bool>>(exp, arg); // return exp2; //}); public async Task <TId> AddAsync(TAggregateRoot aggregateRoot) { using (var ctx = new WbcContext()) { ctx.Set <TAggregateRoot>().Add(aggregateRoot); await ctx.SaveChangesAsync(); return(aggregateRoot.Id); } }
public async Task UpdateAsync(TAggregateRoot aggregateRoot) { using (var ctx = new WbcContext()) { ctx.Set <TAggregateRoot>().Attach(aggregateRoot); ctx.Entry(aggregateRoot).State = EntityState.Modified; await ctx.SaveChangesAsync(); } }
public async Task UpdateRangeAsync(IEnumerable <TAggregateRoot> aggregateRoots) { using (var ctx = new WbcContext()) { foreach (var item in aggregateRoots) { ctx.Set <TAggregateRoot>().Attach(item); ctx.Entry(item).State = EntityState.Modified; } await ctx.SaveChangesAsync(); } }
public async Task RemoveAsync(TId id) { using (var ctx = new WbcContext()) { var result = ctx.Set <TAggregateRoot>() .FirstOrDefault(it => it.Id.Equals(id)); if (result != null) { ctx.Set <TAggregateRoot>().Remove(result); await ctx.SaveChangesAsync(); } } }
public async Task RemoveRangeAsync(IEnumerable <TId> ids) { using (var ctx = new WbcContext()) { var result = ctx.Set <TAggregateRoot>() .Where(it => ids.Contains(it.Id)) .ToArray(); if (result.Length > 0) { ctx.Set <TAggregateRoot>().RemoveRange(result); await ctx.SaveChangesAsync(); } } }