├── .github
└── ISSUE_TEMPLATE.md
├── NuGet.md
├── README.md
├── src
├── EntityFrameworkExtensionsCoreNamespace.cs
├── none.cs
└── readme.txt
└── version.txt
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### Description
2 | Describe the issue or proposed feature.
3 |
4 | ### Exception
5 | If you are seeing an exception, include the full exceptions details (message and stack trace).
6 |
7 | ```
8 | Exception message:
9 | Stack trace:
10 | ```
11 |
12 | ### Fiddle or Project (Optional)
13 | If you are able,
14 |
15 | Provide a Fiddle that reproduces the issue: https://dotnetfiddle.net/jQ4moW
16 |
17 | Or provide a project/solution that we can run to reproduce the issue.
18 | - Make sure the project compile
19 | - Make sure to provide only the code that is required to reproduce the issue, not the whole project
20 | - You can send private code here: info@zzzprojects.com
21 |
22 | Otherwise, make sure to include as much information as possible to help our team to reproduce the issue.
23 |
24 | _Note: More information you provide, faster we can implement a solution._
25 |
26 | ### Further technical details
27 |
28 | - EF version: [EF Core v7.0.13]
29 | - EF Extensions version: [EFE Core v7.100.0.0]
30 | - Database Server version: [SQL Server 2022]
31 | - Database Provider version (NuGet): [Microsoft.Data.SqlClient v5.1.2]
32 |
--------------------------------------------------------------------------------
/NuGet.md:
--------------------------------------------------------------------------------
1 | Evaluate, Compile and Execute C# code at runtime.
2 |
3 | ## Url
4 |
5 | - [Website](https://entityframework-extensions.net/)
6 | - [Getting Started](https://entityframework-extensions.net/overview)
7 | - [Documentation](https://entityframework-extensions.net/bulk-savechanges)
8 | - [Online Examples](https://entityframework-extensions.net/online-examples)
9 |
10 | ## NuGet Packages
11 |
12 | - EF Core: [https://www.nuget.org/packages/Z.EntityFramework.Extensions.EFCore/](https://www.nuget.org/packages/Z.EntityFramework.Extensions.EFCore/)
13 | - EF6: [https://www.nuget.org/packages/Z.EntityFramework.Extensions/](https://www.nuget.org/packages/Z.EntityFramework.Extensions/)
14 | - EF5: [https://www.nuget.org/packages/Z.EntityFramework.Extensions.EF5/](https://www.nuget.org/packages/Z.EntityFramework.Extensions.EF5/)
15 | - EF4: [https://www.nuget.org/packages/Z.EntityFramework.Extensions.EF4/](https://www.nuget.org/packages/Z.EntityFramework.Extensions.EF4/)
16 |
17 | ## Example BulkInsert
18 |
19 | ```csharp
20 | // Easy to use
21 | context.BulkInsert(customers);
22 |
23 | // Easy to customize
24 | context.BulkInsert(invoices, options => options.IncludeGraph = true);
25 | ```
26 |
27 | - Try it (EF Core): [https://dotnetfiddle.net/2eVfFT](https://dotnetfiddle.net/2eVfFT)
28 | - Try it (EF 6): [https://dotnetfiddle.net/bNektu](https://dotnetfiddle.net/bNektu)
29 |
30 | ## Example BulkMerge
31 |
32 | ```csharp
33 | // Easy to use
34 | context.BulkMerge(customers);
35 |
36 | // Easy to customize
37 | context.BulkMerge(customers, options => options.IncludeGraph = true);
38 | ```
39 |
40 | - Try it (EF Core): [https://dotnetfiddle.net/v08Jzy](https://dotnetfiddle.net/v08Jzy)
41 | - Try it (EF 6): [https://dotnetfiddle.net/Aodij2](https://dotnetfiddle.net/Aodij2)
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # What's Entity Framework Extensions?
2 |
3 | Entity Framework Extensions is a library that dramatically improves EF performances by using bulk and batch operations.
4 |
5 | People using this library often report performance enhancement by 50x times and more!
6 |
7 | ## Improve Entity Framework performance with Bulk SaveChanges and Bulk Operations
8 |
9 | Solve Entity Framework performance issue when saving with high performance bulk operations and hundreds of flexibles feature.
10 | - BulkSaveChanges
11 | - BulkInsert
12 | - BulkUpdate
13 | - BulkDelete
14 | - BulkMerge
15 | - DeleteFromQuery
16 | - UpdateFromQuery
17 |
18 | ```csharp
19 | var context = new CustomerContext();
20 | // ... context code ...
21 |
22 | // Easy to use
23 | context.BulkSaveChanges();
24 |
25 | // Easy to customize
26 | context.BulkSaveChanges(operation => operation.BatchSize = 1000);
27 | ```
28 |
29 | ```csharp
30 | // Perform specific bulk operations
31 | context.BulkDelete(customers);
32 | context.BulkInsert(customers);
33 | context.BulkUpdate(customers);
34 |
35 | // Customize Primary Key
36 | context.BulkMerge(customers, operation => {
37 | operation.ColumnPrimaryKeyExpression = customer => customer.Code;
38 | });
39 | ```
40 |
41 | ##### Scalable
42 | SQL Server - Benchmarks
43 |
44 | | Operations | 100 Rows | 1,000 Rows | 10,000 Rows |
45 | | ------------------ | -------: | ---------: | ----------: |
46 | |**BulkSaveChanges** | 20 ms | 200 ms | 2,000 ms |
47 | |**BulkInsert** | 2 ms | 6 ms | 25 ms |
48 | |**BulkUpdate** | 27 ms | 50 ms | 80 ms |
49 | |**BulkDelete** | 25 ms | 45 ms | 70 ms |
50 | |**BulkMerge** | 30 ms | 65 ms | 160 ms |
51 |
52 | ##### Extensible
53 | Support Multiple SQL Providers:
54 | - SQL Server 2008+
55 | - SQL Azure
56 | - SQL Compact
57 | - MySQL
58 | - SQLite
59 | - PostgreSQL
60 | - Oracle
61 |
62 | ## Download
63 |
64 | ### Entity Framework Core (EF Core)
65 |
66 |
67 |
68 | ```
69 | PM> Install-Package Z.EntityFramework.Extensions.EFCore
70 | ```
71 |
72 | ### Entity Framework 6 (EF6)
73 |
74 |
75 |
76 | ```
77 | PM> Install-Package Z.EntityFramework.Extensions
78 | ```
79 |
80 | ### Entity Framework 5 (EF5)
81 |
82 |
83 |
84 | ```
85 | PM> Install-Package Z.EntityFramework.Extensions.EF5
86 | ```
87 |
88 | _* PRO Version unlocked for the current month_
89 |
90 | ## BulkSaveChanges
91 |
92 | ##### Problem
93 | You need to save hundreds or thousands of entities, but you are not satisfied with Entity Framework performance.
94 |
95 | ##### Solution
96 | BulkSaveChanges is exactly like SaveChanges but performs way faster. It’s easy to use, you only need to replace “SaveChanges” by “BulkSaveChanges”, and you are done!
97 |
98 | ```
99 | // Upgrade SaveChanges performance with BulkSaveChanges
100 | var context = new CustomerContext();
101 | // ... context code ...
102 |
103 | // Easy to use
104 | context.BulkSaveChanges();
105 |
106 | // Easy to customize
107 | context.BulkSaveChanges(operation => operation.BatchSize = 1000);
108 | ```
109 |
110 | ##### Scalability
111 | BulkSaveChanges is as fast as SaveChanges with one entity and quickly become **10-50x faster** with hundreds and thousands of entities.
112 |
113 | ## Bulk Operations
114 | ##### Problem
115 | You need even more performance than BulkSaveChanges, save detached entities or save entities in a specific order.
116 |
117 | ##### Solution
118 | Use bulk operations such as bulk insert, update, delete and merge which perform operations on specified entities and bypass the change tracker to increase performance.
119 |
120 | ```csharp
121 | // Perform specific bulk operations on entities
122 | context.BulkDelete(customers);
123 | context.BulkInsert(customers);
124 | context.BulkUpdate(customers);
125 | context.BulkMerge(customers);
126 | ```
127 |
128 | ##### Maintainability
129 | Bulk Operation directly uses the Entity Framework Model. Even if you change column name or change inheritance (TPC, TPH, TPT), Bulk Operation will continue to work as expected.
130 |
131 | ## Custom Key
132 | ##### Problem
133 | You need to perform an update, delete, or merge using a specific custom key like the custom code.
134 |
135 | ##### Solution
136 | Specify your own key by customizing the operation.
137 |
138 | ```csharp
139 | // Use flexible features such as specifying the primary key
140 | context.BulkMerge(customers, operation => {
141 | operation.ColumnPrimaryKeyExpression = customer => customer.Code;
142 | });
143 | ```
144 |
145 | ##### Flexibility
146 | Bulk operations offer hundreds of customization such as BatchSize, Custom Key, Custom Mapping, etc.
147 |
148 | ## PRO Version
149 | _PRO Version unlocked for the current month_
150 |
151 | Features | [PRO Version](https://entityframework-extensions.net/#pro)
152 | -------- | :-------------:
153 | Bulk SaveChanges | Yes
154 | Bulk Insert | Yes
155 | Bulk Update | Yes
156 | Bulk Delete | Yes
157 | Bulk Merge | Yes
158 | DeleteFromQuery | Yes
159 | UpdateFromQuery | Yes
160 | Commercial License | Yes
161 | Royalty-Free | Yes
162 | Support & Upgrades (1 year) | Yes
163 | Learn more about the **[PRO Version](https://entityframework-extensions.net/#pro)**
164 |
165 | ## Contribute
166 |
167 | The best way to contribute is by **spreading the word** about the library:
168 |
169 | - Blog it
170 | - Comment it
171 | - Star it
172 | - Share it
173 |
174 | A **HUGE THANKS** for your help.
175 |
176 | ## More Projects
177 |
178 | - Projects:
179 | - [EntityFramework Extensions](https://entityframework-extensions.net/)
180 | - [Dapper Plus](https://dapper-plus.net/)
181 | - [C# Eval Expression](https://eval-expression.net/)
182 | - Learn Websites
183 | - [Learn EF Core](https://www.learnentityframeworkcore.com/)
184 | - [Learn Dapper](https://www.learndapper.com/)
185 | - Online Tools:
186 | - [.NET Fiddle](https://dotnetfiddle.net/)
187 | - [SQL Fiddle](https://sqlfiddle.com/)
188 | - [ZZZ Code AI](https://zzzcode.ai/)
189 | - and much more!
190 |
191 | To view all our free and paid projects, visit our website [ZZZ Projects](https://zzzprojects.com/).
192 |
--------------------------------------------------------------------------------
/src/EntityFrameworkExtensionsCoreNamespace.cs:
--------------------------------------------------------------------------------
1 | // documentation: https://entityframework-extensions.net/adding-a-namespace-to-entity-framework-extensions
2 |
3 | extern alias EntityFrameworkExtensionsCoreAlias;
4 | using EntityFrameworkExtensionsCoreAlias.Z.BulkOperations;
5 | using EntityFrameworkExtensionsCoreAlias.Z.EntityFramework.Extensions;
6 | using Microsoft.EntityFrameworkCore;
7 | using System.Collections;
8 | using System.Data.Common;
9 | using System.Dynamic;
10 | using System.Linq.Expressions;
11 |
12 | namespace EntityFrameworkExtensionsCoreNamespace
13 | {
14 | public static class Extensions
15 | {
16 | #region BulkDelete
17 |
18 | public static void BulkDelete(this DbContext @this, IEnumerable entities) where T : class
19 | {
20 | EntityFrameworkExtensionsCoreAlias.DbContextExtensions.BulkDelete(@this, entities);
21 | }
22 |
23 | public static void BulkDelete(this DbContext @this, IEnumerable entities, Action> options) where T : class
24 | {
25 | EntityFrameworkExtensionsCoreAlias.DbContextExtensions.BulkDelete(@this, entities, options);
26 | }
27 |
28 | public static void BulkDelete(this DbContext @this, IEnumerable entities, BulkOperationOptions options) where T : class
29 | {
30 | EntityFrameworkExtensionsCoreAlias.DbContextExtensions.BulkDelete(@this, entities, options);
31 | }
32 |
33 | public static void SingleDelete(this DbContext @this, T entity) where T : class
34 | {
35 | EntityFrameworkExtensionsCoreAlias.DbContextExtensions.SingleDelete(@this, entity);
36 | }
37 |
38 | public static void SingleDelete(this DbContext @this, T entity, Action> options) where T : class
39 | {
40 | EntityFrameworkExtensionsCoreAlias.DbContextExtensions.SingleDelete(@this, entity, options);
41 | }
42 |
43 | public static void SingleDelete(this DbContext @this, T entity, BulkOperationOptions options) where T : class
44 | {
45 | EntityFrameworkExtensionsCoreAlias.DbContextExtensions.SingleDelete(@this, entity, options);
46 | }
47 |
48 | public static void BulkDelete(this DbSet @this, IEnumerable entities) where T : class
49 | {
50 | EntityFrameworkExtensionsCoreAlias.DbSetExtensions.BulkDelete(@this, entities);
51 | }
52 |
53 | public static void BulkDelete(this DbSet @this, IEnumerable entities, Action> options) where T : class
54 | {
55 | EntityFrameworkExtensionsCoreAlias.DbSetExtensions.BulkDelete(@this, entities, options);
56 | }
57 |
58 | public static void BulkDelete(this DbSet @this, IEnumerable entities, BulkOperationOptions options) where T : class
59 | {
60 | EntityFrameworkExtensionsCoreAlias.DbSetExtensions.BulkDelete(@this, entities, options);
61 | }
62 |
63 | public static void SingleDelete(this DbSet @this, T entity) where T : class
64 | {
65 | EntityFrameworkExtensionsCoreAlias.DbSetExtensions.SingleDelete(@this, entity);
66 | }
67 |
68 | public static void SingleDelete(this DbSet @this, T entity, Action> options) where T : class
69 | {
70 | EntityFrameworkExtensionsCoreAlias.DbSetExtensions.SingleDelete(@this, entity, options);
71 | }
72 |
73 | public static void SingleDelete(this DbSet @this, T entity, BulkOperationOptions options) where T : class
74 | {
75 | EntityFrameworkExtensionsCoreAlias.DbSetExtensions.SingleDelete(@this, entity, options);
76 | }
77 |
78 | public static void BulkDelete(this DbContext @this, IEnumerable