Reputation: 2491
Which ORM supports sql like batch insert/update/delete:
var user=new UserInfoFields();
var update=user.Update().Set
(
user.Field1=1,
user.Field2="xxxx"
).Where(user.Name=="Jim" && user.Enable==true);
update.Excute();
The corresponding T-sql is:
UPDATE UserInfo
SET
Field1=1,
Field2="xxxx"
WHERE Name='Jim' and Enable=1
Upvotes: 2
Views: 1727
Reputation: 2205
Most of ORMs I know lacks the bulk updates functionality, if you prefer working with EnityFramework like me you can use the Entity Framework Extended Library wich extends many functionalities upon EntityFramework including bulk updates and deletes and Future queries.
Upvotes: 1
Reputation: 59
Checkout BLToolkit -> BLToolkit Linq Extensions - Update
db.Employee
.Where(e => e.Title == "Spectre")
.Update(e => new Northwind.Employee
{
Title = "Commander"
});
or
db.Employee
.Where(e => e.Title == "Spectre")
.Set(e => e.Title, "Commander")
.Update();
=
UPDATE
[e]
SET
[Title] = 'Commander'
FROM
[Employees] [e]
WHERE
[e].[Title] = 'Spectre'
Been using it for 2-3 years now and its great :D
First read this though -> High Level Vision, Global Architecture Strategy & Concept Model Design
Upvotes: 5
Reputation: 71591
PHP ActiveRecord has something like this, but that's PHP. Linq2SQL can be extended to perform simpler batch updates/deletes, but it's not "stock" behavior. Here's the link to an article on the topic: http://www.aneyfamily.com/terryandann/post/2008/04/Batch-Updates-and-Deletes-with-LINQ-to-SQL.aspx. I know for a fact that NHibernate has nothing like this built in, but again, you can extend the Linq provider, and NH also allows HQL and SQL queries as strings, including batch updates/deletes (only problem is they're "magic strings" that are not compiler-checked).
This kind of behavior really goes against what an ORM is designed to do. ORMs exist not to provide compiler-checked queries for all possible SQL operations, but to provide "black-box" encapsulated logic for CRUD operations of single instances of objects, for instance, turning a request for an object into SQL that retrieves the necessary data and hydrates the object. Batch and bulk operations are not their forte by any means.
Upvotes: 2