예제 #1
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();
     }
 }
예제 #2
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();
     }
 }
예제 #3
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();
            }
        }