Skip to content

Commit 764f9b3

Browse files
authored
Create ef6-batch-update.md
1 parent c4054dd commit 764f9b3

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
Permalink: batch-update
3+
---
4+
5+
# Batch Update
6+
7+
> This feature is now available on [Entity Framework Classic - Update from Query](http://entityframework-classic.net/update-from-query). Entity Framework Classic is a supported version from the latest EF6 code base. It supports .NET Framework and .NET Core and overcomes some EF limitations by adding tons of must-haves built-in features.
8+
9+
## Introduction
10+
11+
Updating using Entity Framework can be very slow if you need to update hundreds or thousands of entities with the same expression. Entities are first loaded in the context before being updated which is very bad for the performance and then, they are updated one by one which makes the update operation even worse.
12+
13+
**EF+ Batch Update** updates multiple rows using an expression in a single database roundtrip and without loading entities in the context.
14+
15+
{% include template-example.html %}
16+
```csharp
17+
18+
// using Z.EntityFramework.Plus; // Don't forget to include this.
19+
20+
// UPDATE all users inactive for 2 years
21+
var date = DateTime.Now.AddYears(-2);
22+
ctx.Users.Where(x => x.LastLoginDate < date)
23+
.Update(x => new User() { IsSoftDeleted = 1 });
24+
25+
```
26+
[Try it](https://dotnetfiddle.net/uzsdub)
27+
28+
## Scenarios
29+
30+
- [Query Criteria](scenarios/ef6-batch-update-query-criteria.md)
31+
- [Executing Interceptor](scenarios/ef6-batch-update-executing-interceptor.md)
32+
33+
## Limitations
34+
35+
- **DO NOT** support Complex Type
36+
- **DO NOT** support TPC
37+
- **DO NOT** support TPH
38+
- **DO NOT** support TPT
39+
40+
If you need to use one of this feature, you need to use the library [Entity Framework Extensions](https://entityframework-extensions.net/)
41+
42+
## Requirements
43+
44+
- **EF+ Batch Delete:** Full version or Standalone version
45+
- **Entity Framework Version:** EF5, EF6
46+
- **Minimum Framework Version:** .NET Framework 4
47+
48+
## Conclusion
49+
50+
**EF+ Batch Update** is the most efficient way to update records using an expression. You drastically improve your application performance by removing the need to retrieve and load entities in your context and by performing a single database roundtrip instead of making one for every record.
51+
52+
Need help getting started? [[email protected]](mailto:[email protected])
53+
54+
We welcome all comments, ideas and suggestions to improve our library.

0 commit comments

Comments
 (0)