码迷,mamicode.com
首页 > 数据库 > 详细

Entity Framework + MySQL 使用笔记

时间:2015-01-31 12:01:49      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:

添加:

 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 使用笔记

标签:

原文地址:http://www.cnblogs.com/michaelins/p/4263725.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!