// DELETE api/<controller>/5
[HttpGet]
public void delete(string id)
{
#region 官方推荐写法
/*
var a = entities.base_module.FirstOrDefault(m => m.rowID == id);
if (a != null)
{
entities.base_module.Remove(a);
}
var i = entities.SaveChanges();
*/
#endregion #region 第二种写法,缺点,只能根据主键来删除,因为只能对指定主键的对象进行操作
/*
base_module b = new base_module() { rowID = id };
entities.base_module.Attach(b);
entities.base_module.Remove(b);
var i = entities.SaveChanges();
*/
#endregion #region 第三种写法,和第二种写法一样
base_module c = new base_module() { rowID = id };
entities.Entry(c).State = System.Data.EntityState.Deleted;
entities.SaveChanges();
#endregion
}
05-21 05:38