Beispiel #1
0
        protected virtual IQueryable <TEntity> GetQueryable <TEntity>(
            Expression <Func <TEntity, bool> > filter = null,
            Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > orderBy = null,
            string includeProperties = null,
            int?skip = null,
            int?take = null)
            where TEntity : class
        {
            includeProperties ??= string.Empty;
            IQueryable <TEntity> query = _contextReadOnly.Set <TEntity>();

            if (filter != null)
            {
                query = query.Where(filter);
            }

            foreach (var includeProperty in includeProperties.Split(new char[] { ',' },
                                                                    StringSplitOptions.RemoveEmptyEntries))
            {
                query = query.Include(includeProperty);
            }

            if (orderBy != null)
            {
                query = orderBy(query);
            }

            if (skip.HasValue)
            {
                query = query.Skip(skip.Value);
            }

            if (take.HasValue)
            {
                query = query.Take(take.Value);
            }

            return(query);
        }
 public virtual void Create <TEntity>(TEntity entity, string createdBy = null) where TEntity : class
 {
     _context.Set <TEntity>().Add(entity);
 }