Esempio n. 1
0
 /// <summary>
 /// 获得一个实体
 /// </summary>
 /// <param name="id">id</param>
 /// <returns>实体</returns>
 public SysSample GetById(string id)
 {
     using (DBContainer db = new DBContainer())
     {
         return db.SysSample.SingleOrDefault(a => a.Id == id);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 创建一个实体
 /// </summary>
 /// <param name="db">数据库上下文</param>
 /// <param name="entity">实体</param>
 public int Create(SysSample entity)
 {
     using (DBContainer db = new DBContainer())
     {
         db.SysSample.AddObject(entity);
         return db.SaveChanges();
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 修改一个实体
 /// </summary>
 /// <param name="db">数据库上下文</param>
 /// <param name="entity">实体</param>
 public int Edit(SysSample entity)
 {
     using (DBContainer db = new DBContainer())
     {
         db.SysSample.Attach(entity);
         db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
         return db.SaveChanges();
     }
 }
Esempio n. 4
0
        /// <summary>
        /// 删除一个实体
        /// </summary>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">主键ID</param>
        public int Delete(string id)
        {
            using (DBContainer db = new DBContainer())
            {
                SysSample entity = db.SysSample.SingleOrDefault(a => a.Id == id);
                if (entity != null)
                {

                    db.SysSample.DeleteObject(entity);
                }
                return db.SaveChanges();
            }
        }
Esempio n. 5
0
 /// <summary>
 /// 判断一个实体是否存在
 /// </summary>
 /// <param name="id">id</param>
 /// <returns>是否存在 true or false</returns>
 public bool IsExist(string id)
 {
     using (DBContainer db = new DBContainer())
     {
         SysSample entity = GetById(id);
         if (entity != null)
             return true;
         return false;
     }
 }
Esempio n. 6
0
 /// <summary>
 /// 获取列表
 /// </summary>
 /// <param name="db">数据库上下文</param>
 /// <returns>数据列表</returns>
 public IQueryable<SysSample> GetList(DBContainer db)
 {
     IQueryable<SysSample> list = db.SysSample.AsQueryable();
     return list;
 }