/// <summary> /// 创建 /// </summary> /// <param name="db">实体数据</param> /// <param name="entity">将要创建的对象</param> public virtual void Create(SysEntities db, T entity) { if (entity != null) { db.Set <T>().Add(entity); } }
/// <summary> /// 编辑一个对象 /// </summary> /// <param name="db">实体数据</param> /// <param name="entity">将要编辑的一个对象</param> /// <param name="isAttach">是否附加到数据库上下文</param> public virtual T Edit(SysEntities db, T entity, bool isAttach = true) { if (isAttach) { db.Set <T>().Attach(entity); } db.Entry(entity).State = System.Data.Entity.EntityState.Modified; return(entity); }
/// <summary> /// 获取所有 /// </summary> /// <returns>集合</returns> public virtual IQueryable <T> GetAll(SysEntities db) { return(db.Set <T>().AsQueryable()); }