예제 #1
0
 public List <Car> GetAll(Expression <Func <Car, bool> > filter = null)
 {
     using (CarContext context = new CarContext())
     {
         return(filter == null
         ? context.Set <Car>().ToList()
         : context.Set <Car>().Where(filter).ToList());
     }
 }
예제 #2
0
 public Car Get(Expression <Func <Car, bool> > filter)
 {
     using (CarContext context = new CarContext())
     {
         return(context.Set <Car>().SingleOrDefault(filter));
     }
 }
예제 #3
0
        public TEntity Add(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            _context.Set <TEntity>().Add(entity);
            return(entity);
        }
예제 #4
0
        /// <summary>
        /// Gets all entity records with included entities
        /// </summary>
        /// <param name="includes">included entities</param>
        /// <returns>IQueryable of all entity records with included entities, if includes is null this function is equal GetAll</returns>
        public IQueryable <TEntity> Query(params Expression <Func <TEntity, object> >[] includes)
        {
            DbSet <TEntity>      dbSet = context.Set <TEntity>();
            IQueryable <TEntity> query = dbSet;

            foreach (var include in includes)
            {
                query = query.Include(include);
            }

            return(query ?? dbSet);
        }
예제 #5
0
 public GenericRepositiory(CarContext context)
 {
     _context = context;
     _dbSet   = context.Set <T>();
 }
예제 #6
0
 public Repository(CarContext _context)
 {
     context    = _context;
     dbEntities = context.Set <TEntity>();
 }
예제 #7
0
 /// <summary>
 /// IQueryable延迟加载集合,调用时才会去加载至内存
 /// List查询后会立即加载至内存中
 /// </summary>
 /// <returns></returns>
 public IQueryable <T> GetEntitys(Expression <Func <T, bool> > lambdaWhere)
 {
     //context.UserInfoes.Where(lambdaWhere);
     return(context.Set <T>().Where(lambdaWhere));
 }