// GET: Employee
        public async Task <IActionResult> Index()
        {
            List <Department> departments = await _context.Set <Department>()
                                            .Where(d => d.Employees.Any(e => e.EmployeeName == "Tanvir Ahmad")).ToListAsync();

            await _repository.GetLongCountAsync <Employee>();

            Specification <Employee> specification = new Specification <Employee>();

            specification.Conditions.Add(e => e.EmployeeName.Contains("Tanvir"));
            specification.Includes = ep => ep.Include(e => e.Department);
            specification.OrderBy  = sp => sp.OrderBy(e => e.EmployeeName).ThenBy(e => e.DepartmentName);
            specification.Skip     = 0;
            specification.Take     = 10;

            List <Employee> lists           = _repository.GetQueryable <Employee>().ToList();
            Employee        entityListAsync = await _repository.GetByIdAsync <Employee>(1, true);



            Employee v1 = await _repository.GetByIdAsync <Employee>(1);

            await _context.Set <Employee>().Where(e => e.EmployeeId == 1).ToListAsync();

            _context.Set <Employee>().Where(e => e.EmployeeId == 1).ToList();
            //await _unitOfWork.Repository<Employee>().GetEn
            return(View(lists));
        }
Esempio n. 2
0
        public ActionResult <IEnumerable <string> > Get()
        {
            _context.Set <DemoModel>().Add(new DemoModel()
            {
                //Id = 1,
                CustomerName     = "levy",
                IdentityCardType = 1,
            });
            var res = _context.SaveChanges();

            return(Succeed(new string[] { "value1", res + "" }));
        }
        // GET: Employee
        public async Task <IActionResult> Index()
        {
            Specification <Employee> specification = new Specification <Employee>();

            List <Employee> entityListAsync = await _unitOfWork.Repository <Employee>()
                                              .GetProjectedEntityListAsync(specification, e => new Employee
            {
                EmployeeId   = e.EmployeeId,
                EmployeeName = e.EmployeeName
            });

            await _unitOfWork.Repository <Employee>().GetEntityListAsync();

            await _context.Set <Employee>().Where(e => e.EmployeeId == 1).ToListAsync();

            _context.Set <Employee>().Where(e => e.EmployeeId == 1).ToList();
            //await _unitOfWork.Repository<Employee>().GetEn
            return(View(entityListAsync));
        }
Esempio n. 4
0
        // GET: Employee
        public async Task <IActionResult> Index()
        {
            Specification <Employee> specification = new Specification <Employee>();
            //specification.Conditions.Add(e => e.EmployeeName.Contains("Tanvir"));
            //specification.Includes = ep => ep.Include(e => e.Department);
            //specification.OrderBy = sp => sp.OrderBy(e => e.EmployeeName).ThenBy(e => e.DepartmentName);
            //specification.Skip = 0;
            //specification.Take = 10;

            Employee entityListAsync = await _unitOfWork.Repository <Employee>().GetEntityByIdAsync(1, true);

            long v = _context.Set <Employee>().Select(e => e.EmployeeId).FirstOrDefault();

            long employeeId = await _unitOfWork.Repository <Employee>().GetProjectedEntityByIdAsync(1, e => e.EmployeeId);

            await _context.Set <Employee>().Where(e => e.EmployeeId == 1).ToListAsync();

            _context.Set <Employee>().Where(e => e.EmployeeId == 1).ToList();
            //await _unitOfWork.Repository<Employee>().GetEn
            return(View(entityListAsync));
        }
Esempio n. 5
0
        protected virtual IQueryable <TEntity> GetQueryable(
            Expression <Func <TEntity, bool> > filter = null,
            Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > orderBy = null,
            string[] includeProperties = null,
            int?skip = null,
            int?take = null)
        {
            IQueryable <TEntity> query = dbContext.Set <TEntity>();

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

            foreach (var includeProperty in includeProperties ?? new string[] { })
            {
                if (!string.IsNullOrWhiteSpace(includeProperty.Trim()))
                {
                    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);
        }
Esempio n. 6
0
 /// <summary>
 /// 为指定的类型返回 System.Data.Entity.DbSet,这将允许对上下文中的给定实体执行 CRUD 操作
 /// </summary>
 /// <typeparam name="TEntity">实体类型</typeparam>
 /// <returns>指定类型的DbSet实例</returns>
 public DbSet <TEntity> Set <TEntity>() where TEntity : Entity
 {
     return(_dbContext.Set <TEntity>());
 }
Esempio n. 7
0
 public virtual T GetById(int id)
 {
     return(_dbContext.Set <T>().Find(id));
 }
Esempio n. 8
0
        private DbSet <T> entities;  //specific set

        protected EntityBaseRepository(DemoDbContext db)
        {
            entities = db.Set <T>();
            this.db  = db;
        }
Esempio n. 9
0
 public Repository(DemoDbContext db)
 {
     _db    = db;
     _table = _db.Set <T>();
 }
Esempio n. 10
0
 public EfDbSetWrapper(DemoDbContext efDbContext)
 {
     this.efDbContext = efDbContext;
     this.dbSet       = efDbContext.Set <T>();
 }