Exemplo n.º 1
0
 /// <summary>
 /// 创建一个实体
 /// </summary>
 /// <param name="entity">数据库上下文</param>
 /// <returns>执行返回结果影响行数</returns>
 public int Create(test_sys_sample entity)
 {
     using (DBContainer db = new DBContainer())
     {
         db.Set <test_sys_sample>().Add(entity);
         return(db.SaveChanges());
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 修改一个实体
 /// </summary>
 /// <param name="entity">数据库上下文</param>
 /// <returns>执行返回结果影响行数</returns>
 public int Edit(test_sys_sample entity)
 {
     using (DBContainer db = new DBContainer())
     {
         db.Set <test_sys_sample>().Attach(entity);
         db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
         return(db.SaveChanges());
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// 删除一个实体
 /// </summary>
 /// <param name="id">主键ID</param>
 /// <returns>执行返回结果影响行数</returns>
 public int Delete(long id)
 {
     using (DBContainer db = new DBContainer())
     {
         test_sys_sample entity = db.test_sys_sample.SingleOrDefault(a => a.Id == id);
         db.Set <test_sys_sample>().Remove(entity);
         return(db.SaveChanges());
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 判断实体是否存在
 /// </summary>
 /// <param name="id">主键ID</param>
 /// <returns>返回结果</returns>
 public bool IsExist(long id)
 {
     using (DBContainer db = new DBContainer())
     {
         test_sys_sample entity = GetById(id);
         if (entity != null)
         {
             return(true);
         }
         return(false);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// 根据ID获得一个实体
 /// </summary>
 /// <param name="id">id</param>
 /// <returns>实体</returns>
 public test_sys_sample GetById(long id)
 {
     if (IsExist(id))
     {
         test_sys_sample entity = _iSysSampleDAL.GetById(id);
         return(entity);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// 修改一个实体
 /// </summary>
 /// <param name="errors">持久的错误信息</param>
 /// <param name="model">模型</param>
 /// <returns>是否成功</returns>
 public bool Edit(test_sys_sample entity)
 {
     try
     {
         if (_iSysSampleDAL.Edit(entity) == 1)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         //ExceptionHander.WriteException(ex);
         return(false);
     }
 }