添加:
using (var edm = new NorthwindEntities()) { Customers c = new Customers { CustomerID = "c#", City = "成都市", Address = "中国四川省", CompanyName = "cnblogs", Country = "中国", Fax = "", Phone = "", PostalCode = "", Region = "天府广场", ContactName = "风车车.Net" }; edm.AddToCustomers(c); int result = edm.SaveChanges();}
删除:
using (var edm = new NorthwindEntities()) { Customers deletec = edm.Customers.FirstOrDefault(cc => cc.CustomerID == "c2"); edm.DeleteObject(deletec); int result = edm.SaveChanges(); }
修改:
using (var edm = new NorthwindEntities())
{
Customers addc = edm.Customers.FirstOrDefault(cc => cc.CustomerID == "c2");
addc.City = "CD";
addc.ContactName = "cnblogs";
addc.Country = "CN";
int result = edm.SaveChanges();
}
分页+排序:
private static List<Post> GetPostList(int pageIndex, int pageSize)
{
int startRow = (pageIndex - ) * pageSize;
using (var db = new EdiBlogEntities())
{
var query = db.Post.OrderByDescending(p => p.PubDate).Skip(startRow).Take(pageSize);
return query.ToList();
}
}