首页新闻找找看学习计划

扩展 entity-framwork ,实现批量修改、删除、插入

0
悬赏园豆:20 [已关闭问题]

怎样扩展entity-framework,能够实现如下功能:

db.Users.Delete(o=>o.sex=="girl") //删除所有性别为“girl"的用户
db.Users.Update(o=>o.sex="girl")  //修改所有用户性别为“girl"

批量删除、修改、插入数据,在linq to sql里面是可以的,但在entity-framework里面就不知道怎么弄了

鬼--哥的主页 鬼--哥 | 初学一级 | 园豆:185
提问于:2010-08-02 10:38
< >
分享
其他回答(3)
0

自己写个扩展方法,解析LinqExpression,组装EQL,再执行

最近比较忙,有时间写个

钧梓昊逑 | 园豆:945 (小虾三级) | 2010-08-02 12:29
楼上的高手,能不能指点下,我实在是搞不定
支持(0) 反对(0) 鬼--哥 | 园豆:185 (初学一级) | 2010-08-03 18:18
0

http://www.cnblogs.com/zh-xiaot/archive/2011/08/06/2129601.html这篇文章实现了你要的功能,你可以看下

xiaot_zh | 园豆:205 (菜鸟二级) | 2011-08-19 22:44
0

db.saveChanges()

更具实体模型中实体状态(Deleted,Modified...),对数据库中进行相应的操作

江南_雾里看花 | 园豆:394 (菜鸟二级) | 2012-06-28 16:10

插入:

NorthwindDataContext db = new NorthwindDataContext();
var newCustomer = new Customer
{
    CustomerID = "MCSFT",
    CompanyName = "Microsoft",
    ContactName = "John Doe",
    ContactTitle = "Sales Manager",
    Address = "1 Microsoft Way",
    City = "Redmond",
    Region = "WA",
    PostalCode = "98052",
    Country = "USA",
    Phone = "(425) 555-1234",
    Fax = null
};
修改:

Customer cust =
    db.Customers.First(c => c.CustomerID == "ALFKI");
cust.ContactTitle = "Vice President";
db.SubmitChanges();

删除:
OrderDetail orderDetail =
    db.OrderDetails.First
    (c => c.OrderID == 10255 && c.ProductID == 36);
db.OrderDetails.DeleteOnSubmit(orderDetail);
db.SubmitChanges();


支持(0) 反对(0) 江南_雾里看花 | 园豆:394 (菜鸟二级) | 2012-06-29 08:29
0

看下这个组件:http://weblogs.asp.net/pwelter34/archive/2011/11/29/entity-framework-batch-update-and-future-queries.aspx 批量更新删除  NuGet: EntityFramework.Extended

eflay | 园豆:189 (初学一级) | 2013-03-26 11:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册