/// <summary> /// Generic Find() method to retrieve specific information through expression from the database /// </summary> /// <param name="predicate">Ex: p => p.AccountId == 1</param> /// <returns>Returns the object entity called to the database</returns> public async virtual Task <IEnumerable <T> > Find(Expression <Func <T, bool> > predicate) { return(await _context.Set <T>() .AsNoTracking() .AsQueryable() .Where(predicate) .ToListAsync()); }
//详情 public ActionResult Details(int id) { //SysUser sysUser = db.SysUsers.Find(id); //EF提供一组方法用来执行原生的SQL string query = "select * from [CuiPro].[dbo].[SysUser] where ID=@id"; SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@id", id) }; //var sysUser = db.SysUsers.SqlQuery(query, paras).SingleOrDefault(); //DbSet.SqlQuery查询并返回Entities var sysUserEntity = db.Set <SysUser>(); var sysUser = sysUserEntity.SqlQuery(query, paras).SingleOrDefault(); return(View(sysUser)); }
public GenericRepository(AccountContext context) { this.context = context; this.dbSet = context.Set <TEntity>(); }
public virtual IEnumerable <T> GetAll() { return(_context.Set <T>().AsEnumerable()); }
public AccountRepository(AccountContext context) { _context = context; _accountEntity = context.Set <Models.Account>(); }
public bool Exists(Func <Account, bool> expression) { return(_context.Set <Account>().Any(expression)); }
/// <summary> /// /// </summary> /// <param name="context"></param> public Repository(AccountContext context) { _dbSet = context.Set <TEntity>(); }
// GET: Accounts/Create public IActionResult Create() { ViewData["CustomerID"] = new SelectList(_context.Set <Customer>(), "CustomerID", "CustomerName"); return(View()); }
public async Task Add(T entity) { await _context.Set <T>().AddAsync(entity); await _context.SaveChangesAsync(); }
public async Task <Acc> Get(Guid id) => await _accountContext.Set <Acc>() .FirstOrDefaultAsync(acc => acc.Id == id);
public GenericRepository(AccountContext context) { db = context; DbSet = db.Set <T>(); }
public void Insert(T obj) { _context.Set <T>().Add(obj); _context.SaveChanges(); }
public TransactionsRepository(AccountContext context) { _context = context; _transactionsEntity = context.Set <Transaction>(); }
public GenericRepository(AccountContext Context) { this.Context = Context; this.dbset = Context.Set <TEntity>(); }