怎样使用Entityframework.Extended

这个插件真的非常有用,我们能够使用下面语法来简化我们的工作,下面不过演示样例:

Deleting

<strong>//delete all users where FirstName matches
context.Users.Delete(u => u.FirstName == "firstname");
</strong>

Update

//update all tasks with status of 1 to status of 2
context.Tasks.Update(
    t => t.StatusId == 1, 
    t2 => new Task {StatusId = 2});

//example of using an IQueryable as the filter for the update
var users = context.Users.Where(u => u.FirstName == "firstname");
context.Users.Update(users, u => new User {FirstName = "newfirstname"});


从上述代码中,我们能够看到,当我们须要删除或编辑符合某一条件的数据时(可能有多条数据),我们能够一次性的进行操作。这里仅仅是简单的演示,很多其它的信息请查看:

https://github.com/loresoft/EntityFramework.Extended

以下我们来介绍怎样安装:

首先,我们须要在Package Manager Console中执行以下命令来将该扩展安装到我们的项目中:

PM> Install-Package EntityFramework.Extended


然后,成功安装后。我们须要在代码页中引用下面命名空间才干使用:

using EntityFramework.Extensions;

Ok, 如今已经能够使用了。




原文地址:https://www.cnblogs.com/cxchanpin/p/7221593.html