Exemplo n.º 1
0
        public IList <T> GetMany(IEnumerable <TKey> ids)
        {
            var idList = ids as IList <TKey> ?? ids.ToList();

            if (idList.IsEmpty())
            {
                return(new List <T>());
            }

            var result = _dbContext.Set <T>().Join(
                idList,
                ent => ent.Id,
                id => id,
                (ent, id) => ent);

            return(result.ToList());
        }
Exemplo n.º 2
0
        public async Task DeleteAsync(IEnumerable <T> entities, IntranetDbContext context = null)
        {
            var isExternalContext = context != null;

            context = context ?? DbContextAsync;

            var set = context.Set <T>();

            var entityList = entities.ToList();

            entityList.ForEach(e => set.Attach(e));

            set.RemoveRange(entityList);

            await SaveAsync(context);

            if (!isExternalContext)
            {
                context.Dispose();
            }
        }
Exemplo n.º 3
0
 public SqlRepository(IntranetDbContext dbContext)
 {
     _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     _dbSet     = dbContext.Set <T>();
 }