views:

29

answers:

1

how to extend entity framework ,To achieve this effect

db.Users.Delete(o=>o.sex=="girl") db.Users.Update(o=>o.sex="girl")

Can batch modification and deletion, insert data


怎样扩展entity framework ,可以实现批量修改、删除和插入数据

A: 

In Entity Framework 4 that's part of .NET 4.0 there is a method on the ObjectContext

ExecuteStoredCommand(string cmdText, object[] parameters)

This allows to execute set based operations directly against your datastore.

In your example you could do something like:

db.ExecuteStoreCommand("DELETE FROM [User] WHERE Sex = '{0}'", new[] {"girl"});
willbt