/// <summary> /// 添加一个实体 /// </summary> /// <param name="entity">实体</param> /// <returns></returns> public int Create(SysSample entity) { using (AppsDBEntities db = new AppsDBEntities()) { db.Set <SysSample>().Add(entity); return(db.SaveChanges()); } }
/// <summary> /// 修改一个实体 /// </summary> /// <param name="entity">实体</param> /// <returns></returns> public int Edit(SysSample entity) { using (AppsDBEntities db = new AppsDBEntities()) { db.Set <SysSample>().Attach(entity); db.Entry <SysSample>(entity).State = EntityState.Modified; return(db.SaveChanges()); } }
/// <summary> /// 删除一条实体 /// </summary> /// <param name="id">实体ID</param> /// <returns></returns> public int Delete(string id) { using (AppsDBEntities db = new AppsDBEntities()) { SysSample entity = db.SysSample.SingleOrDefault(a => a.Id == id); db.Set <SysSample>().Remove(entity); return(db.SaveChanges()); } }