EF删除数据

ShopEntities db = new ShopEntities();
var customers = from c in db.Customer
where c.ID == 21
select c;
var customer = customers.FirstOrDefault();
if (customer != null)
{
//删除标记
db.Entry(customer).State = System.Data.EntityState.Deleted;//删除标记
db.SaveChanges();
}

ShopEntities db = new ShopEntities();
var customers = from c in db.Customer
where c.ID == 22
select c;
var customer = customers.FirstOrDefault();
if (customer != null)
{
customer.CustomerName = "lisi88888";
db.Entry(customer).State = System.Data.EntityState.Modified;//修改标记
db.SaveChanges();
}
}

Model-First(先创建模型,然后再根据模型创建数据库。如果主键ID是Guid类型在创建模型时,将相应的属性取消自增StoreGeneratedPattern设置为none)

posted on 2015-02-23 00:48  木屐  阅读(252)  评论(0编辑  收藏  举报

导航