首页 > 代码库 > Entity Framework + MySQL 使用笔记
Entity Framework + MySQL 使用笔记
添加:
1 using (var edm = new NorthwindEntities()) 2 3 { 4 5 Customers c = new Customers { CustomerID = "c#", City = "成都市", Address = "中国四川省", CompanyName = "cnblogs", Country = "中国", Fax = "10086", Phone = "1008611", PostalCode = "610000", Region = "天府广场", ContactName = "风车车.Net" }; 6 7 edm.AddToCustomers(c); 8 9 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();}
修改:
1 using (var edm = new NorthwindEntities())2 {3 Customers addc = edm.Customers.FirstOrDefault(cc => cc.CustomerID == "c2");4 addc.City = "CD";5 addc.ContactName = "cnblogs";6 addc.Country = "CN";7 int result = edm.SaveChanges();8 }
分页+排序:
1 private static List<Post> GetPostList(int pageIndex, int pageSize)2 {3 int startRow = (pageIndex - 1) * pageSize;4 using (var db = new EdiBlogEntities())5 {6 var query = db.Post.OrderByDescending(p => p.PubDate).Skip(startRow).Take(pageSize);7 return query.ToList();8 }9 }
Entity Framework + MySQL 使用笔记
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。