Пример #1
0
 public int Delete(int id)
 {
     using (DbContainer db = new DbContainer())
     {
         var entity = GetById(id);
         if (entity != null)
         {
             //改变实体状态,否则无法删除(报错)
             db.Entry(entity).State = EntityState.Deleted;
             db.Set<SysSample>().Remove(entity);
         }
         return db.SaveChanges();
     }
 }
Пример #2
0
 public int Edit(SysSample entity)
 {
     try
     {
         using (DbContainer db = new DbContainer())
         {
             db.Set<SysSample>().Attach(entity);
             db.Entry(entity).State = EntityState.Modified;
             return db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         return 0;
     }
 }
Пример #3
0
 public virtual bool Create(T model)
 {
     db.Set <T>().Add(model);
     return(db.SaveChanges() > 0);
 }