Exemplo n.º 1
0
 /// <summary>新增
 /// 新增
 /// </summary>
 /// <param name="entity">实体</param>
 /// <returns>返回受影响行数</returns>
 public bool Add <T>(T entity) where T : class
 {
     using (SysDb <T> db = new SysDb <T>(strConn))
     {
         db.Entry <T>(entity).State = EntityState.Added;
         return(db.SaveChanges() > 0);
     }
 }
Exemplo n.º 2
0
 /// <summary>根据条件删除
 /// 根据条件删除
 /// </summary>
 /// <param name="deleWhere">删除条件</param>
 /// <returns>返回受影响行数</returns>
 public bool DeleteByConditon <T>(Expression <Func <T, bool> > deleWhere) where T : class
 {
     using (SysDb <T> db = new SysDb <T>(strConn))
     {
         List <T> entitys = db.Set <T>().Where(deleWhere).ToList();
         entitys.ForEach(m => db.Entry <T>(m).State = EntityState.Deleted);
         return(db.SaveChanges() > 0);
     }
 }
Exemplo n.º 3
0
 /// <summary>删除
 /// 删除
 /// </summary>
 /// <param name="entity">实体</param>
 /// <returns>返回受影响行数</returns>
 public bool Delete <T>(T entity) where T : class
 {
     using (SysDb <T> db = new SysDb <T>(strConn))
     {
         db.Set <T>().Attach(entity);
         db.Entry <T>(entity).State = EntityState.Deleted;
         return(db.SaveChanges() > 0);
     }
 }