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
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
db.SaveChanges();
}
}
Model-First(先创建模型,然后再根据模型创建数据库。如果主键ID是Guid类型在创建模型时,将相应的属性取消自增StoreGeneratedPattern设置为none)