diff --git a/docs2/pages/ef-core-docs/documentations/ef-core-audit.md b/docs2/pages/ef-core-docs/documentations/audit/ef-core-audit.md similarity index 98% rename from docs2/pages/ef-core-docs/documentations/ef-core-audit.md rename to docs2/pages/ef-core-docs/documentations/audit/ef-core-audit.md index 6b9db94d..dbd92697 100644 --- a/docs2/pages/ef-core-docs/documentations/ef-core-audit.md +++ b/docs2/pages/ef-core-docs/documentations/audit/ef-core-audit.md @@ -1,3 +1,6 @@ +--- +Permalink: ef-core-audit +--- # Audit ## Introduction diff --git a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-autosave.md b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-autosave.md similarity index 99% rename from docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-autosave.md rename to docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-autosave.md index ae6bb2f5..d7b91228 100644 --- a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-autosave.md +++ b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-autosave.md @@ -1,3 +1,7 @@ +--- +Permalink: ef-core-audit-autosave +--- + # AutoSave Audit ## Problem diff --git a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-customization.md b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-customization.md similarity index 98% rename from docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-customization.md rename to docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-customization.md index 893d528b..0b010ac0 100644 --- a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-customization.md +++ b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-customization.md @@ -1,3 +1,7 @@ +--- +Permalink: ef-core-audit-customization +--- + # Audit Customization ## Problem diff --git a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-data-annotations.md b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-data-annotations.md similarity index 94% rename from docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-data-annotations.md rename to docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-data-annotations.md index 47a443a0..fa1823ca 100644 --- a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-data-annotations.md +++ b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-data-annotations.md @@ -1,3 +1,7 @@ +--- +Permalink: ef-core-data-annotations +--- + # Data Annotations ## Problem diff --git a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-ef-extensions.md b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-ef-extensions.md similarity index 96% rename from docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-ef-extensions.md rename to docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-ef-extensions.md index 3ae866ea..a75622c6 100644 --- a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-ef-extensions.md +++ b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-ef-extensions.md @@ -1,3 +1,7 @@ +--- +Permalink: ef-core-audit-ef-extensions +--- + # Audit + Entity Framework Extensions If you are using Entity Framework Extensions, it is still possible to use the EF+ Audit features. diff --git a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-exclude-include-entity.md b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-exclude-include-entity.md similarity index 94% rename from docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-exclude-include-entity.md rename to docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-exclude-include-entity.md index e720b227..099369c7 100644 --- a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-exclude-include-entity.md +++ b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-exclude-include-entity.md @@ -1,3 +1,7 @@ +--- +Permalink: ef-core-audit-exclude-include-entity +--- + # Exclude & Include Entity ## Problem diff --git a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-exclude-include-property.md b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-exclude-include-property.md similarity index 96% rename from docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-exclude-include-property.md rename to docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-exclude-include-property.md index 0bde5a97..c43e34ae 100644 --- a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-exclude-include-property.md +++ b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-exclude-include-property.md @@ -1,3 +1,7 @@ +--- +Permalink: ef-core-audit-exclude-include-property +--- + # Exclude & Include Property ## Problem diff --git a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-format-value.md b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-format-value.md similarity index 94% rename from docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-format-value.md rename to docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-format-value.md index c1c317ac..1f2e0aa0 100644 --- a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-format-value.md +++ b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-format-value.md @@ -1,3 +1,7 @@ +--- +Permalink: ef-core-audit-format-value +--- + # Format Value ## Problem diff --git a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-ignore-events.md b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-ignore-events.md similarity index 94% rename from docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-ignore-events.md rename to docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-ignore-events.md index ef8e62d8..371f8fc0 100644 --- a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-ignore-events.md +++ b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-ignore-events.md @@ -1,3 +1,7 @@ +--- +Permalink: ef-core-audit-ignore-events +--- + # Ignore Events ### Problem diff --git a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-property-unchanged.md b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-property-unchanged.md similarity index 92% rename from docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-property-unchanged.md rename to docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-property-unchanged.md index 5003fcc3..ef5b2a71 100644 --- a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-property-unchanged.md +++ b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-property-unchanged.md @@ -1,3 +1,7 @@ +--- +Permalink: ef-core-audit-property-unchanged +--- + # Property Unchanged ## Problem diff --git a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-retrieve-audit-entries-for-specific-item.md b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-retrieve-audit-entries-for-specific-item.md similarity index 94% rename from docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-retrieve-audit-entries-for-specific-item.md rename to docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-retrieve-audit-entries-for-specific-item.md index 61b340bf..5156b312 100644 --- a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-retrieve-audit-entries-for-specific-item.md +++ b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-retrieve-audit-entries-for-specific-item.md @@ -1,3 +1,7 @@ +--- +Permalink: ef-core-audit-retrieve-audit-entries-for-specific-item +--- + # Retrieve AuditEntries for specific item ## Problem diff --git a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-soft-add-soft-delete.md b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-soft-add-soft-delete.md similarity index 93% rename from docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-soft-add-soft-delete.md rename to docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-soft-add-soft-delete.md index b65072de..3beb2094 100644 --- a/docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audit-soft-add-soft-delete.md +++ b/docs2/pages/ef-core-docs/documentations/audit/scenarios/ef-core-audit-soft-add-soft-delete.md @@ -1,3 +1,7 @@ +--- +Permalink: ef-core-audit-soft-add-soft-delete +--- + # Soft Add & Soft Delete ## Problem diff --git a/docs2/pages/ef-core-docs/documentations/batch-delete/ef-core-batch-delete.md b/docs2/pages/ef-core-docs/documentations/batch-delete/ef-core-batch-delete.md new file mode 100644 index 00000000..908e0a65 --- /dev/null +++ b/docs2/pages/ef-core-docs/documentations/batch-delete/ef-core-batch-delete.md @@ -0,0 +1,71 @@ +--- +Permalink: ef-core-batch-delete +--- + +# Batch Delete + +> This feature is now available on [Entity Framework Classic - Delete from Query](http://entityframework-classic.net/delete-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. + +## Introduction + +Deleting using Entity Framework Core can be very slow if you need to delete hundreds or thousands of entities. Entities are first loaded in the context before being deleted which is very bad for the performance and then, they are deleted one by one which makes the delete operation even worse. + +**EF+ Batch Delete** deletes multiple rows in a single database roundtrip and without loading entities in the context. + +{% include template-example.html %} +```csharp +// using Z.EntityFramework.Plus; // Don't forget to include this. + +// DELETE all users inactive for 2 years +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .Delete(); + +// DELETE using a BatchSize +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .Delete(x => x.BatchSize = 1000); + +``` +[Try it](https://dotnetfiddle.net/8qqyPw) + +## Scenarios + + - [Query Criteria](scenarios/ef-core-batch-delete-query-criteria.md) + - [Batch Size](scenarios/ef-core-batch-delete-using-batch-size.md) + - [Batch Delay Interval](scenarios/ef-core-batch-delete-using-batch-delay-interval.md) + - [Executing Interceptor](scenarios/ef-core-batch-delete-executing-interceptor.md) + - [EF Core InMemory](scenarios/ef-core-batch-delete-inmemory.md) + +## Limitations + + - **DO NOT** support Complex Type + - **DO NOT** support TPC + - **DO NOT** support TPH + - **DO NOT** support TPT + +If you need to use one of this feature, you need to use the library [Entity Framework Extensions](https://entityframework-extensions.net/) + +### EF Core & Client Evaluation + + _Do not use this feature if Client Evaluation is enabled_ + +`Batch Delete` use the SQL generated by EF Core. When a filter is made on client-side, it means the filtering happens in the application and not in the SQL executed. + +In other words, even if you put a filter, all rows tables could be potentially deleted if the filter is made on the client-side. + +We always recommend to [disable the client evaluation](https://docs.microsoft.com/en-us/ef/core/querying/client-eval#optional-behavior-throw-an-exception-for-client-evaluation) to avoid performance issue in your application. + +## Requirements + +- **EFCore+ Batch Delete:** Full version or Standalone version +- **Entity Framework Version:** EFCore +- **Minimum Framework Version:** .NET Framework 4 + +## Conclusion + +**EF+ Batch Delete** is the most efficient way to delete records. 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 one for every record. + +Need help getting started? [info@zzzprojects.com](mailto:info@zzzprojects.com) + +We welcome all comments, ideas and suggestions to improve our library. diff --git a/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-executing-interceptor.md b/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-executing-interceptor.md new file mode 100644 index 00000000..30f4bd14 --- /dev/null +++ b/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-executing-interceptor.md @@ -0,0 +1,27 @@ +--- +Permalink: ef-core-batch-delete-executing-interceptor +--- + +# Executing Interceptor + +### Problem + +You need to log the DbCommand information or change the CommandText, Connection or Transaction before the batch is executed. + +### Solution + +The **Executing** property intercepts the DbCommand with an action before being executed. + + +{% include template-example.html %} +```csharp + +// using Z.EntityFramework.Plus; // Don't forget to include this. + +string commandText +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .Delete(x => { x.Executing = command => commandText = command.CommandText; }); + +``` +[Try it](https://dotnetfiddle.net/KrtT0e) diff --git a/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-inmemory.md b/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-inmemory.md new file mode 100644 index 00000000..8caf7037 --- /dev/null +++ b/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-inmemory.md @@ -0,0 +1,29 @@ +--- +Permalink: ef-core-batch-delete-inmemory +--- + +# EF Core InMemory + +### Problem + +You want to use **BatchDelete** with In Memory Testing for EF Core. + +### Solution + +Specify a DbContext factory in the **BatchDeleteManager** to enable BatchDelete with In Memory. A DbContext factory must be + +{% include template-example.html %} +```csharp + +// Options +var db = new DbContextOptionsBuilder(); +db.UseInMemoryDatabase(); + +// Specify InMemory DbContext Factory +BatchDeleteManager.InMemoryDbContextFactory = () => new MyContext(db.Options); + +// Use the same code as with Relational Database +var _context = new MyContext(db.Options); +_context.Foos.Delete(); + +``` diff --git a/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-query-criteria.md b/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-query-criteria.md new file mode 100644 index 00000000..7c0a159a --- /dev/null +++ b/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-query-criteria.md @@ -0,0 +1,55 @@ +--- +Permalink: ef-core-batch-delete-query-criteria +--- + +# Batch Delete using Query Criteria + +### Problem + +You need to delete one or millions of records based on a query criteria. + +### Solution + +The **Delete** IQueryable extension methods deletes rows matching the query criteria without loading entities in the context. + +{% include template-example.html %} +```csharp + +// using Z.EntityFramework.Plus; // Don't forget to include this. + +// DELETE all users +ctx.Users.Delete(); + +// DELETE all users inactive for 2 years +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .Delete(); + +``` +[Try it](https://dotnetfiddle.net/HQauA0) + +## Batch DeleteAsync + +### Problem + +You need to delete one or millions of records based on a query criteria asynchronously. + +### Solution + +The **DeleteAsync** IQueryable extension methods deletes asynchronously rows matching the query criteria without loading entities in the context. + +{% include template-example.html %} +```csharp + +// using Z.EntityFramework.Plus; // Don't forget to include this. + +// DELETE all users +ctx.Users.DeleteAsync(); + +// DELETE all users inactive for 2 years +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .DeleteAsync(); + +``` +[Try it](https://dotnetfiddle.net/Xdxjg1) diff --git a/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-using-batch-delay-interval.md b/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-using-batch-delay-interval.md new file mode 100644 index 00000000..44e1546f --- /dev/null +++ b/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-using-batch-delay-interval.md @@ -0,0 +1,28 @@ +--- +Permalink: ef-core-batch-delete-using-batch-delay-interval +--- + +# Batch Delay Interval + +### Problem + +You need to delete millions of records but also need to pause between batches to let other applications keep on performing their CRUD operations. + +### Solution + +The **BatchDelayInterval** property sets the amount of time (in milliseconds) to wait before starting the next delete batch. + +Default Value = 0 + +{% include template-example.html %} +```csharp + +// using Z.EntityFramework.Plus; // Don't forget to include this. + +// Pause 2 seconds between every batch +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .Delete(x => x.BatchDelayInterval = 2000); + +``` +[Try it](https://dotnetfiddle.net/3iRApA) diff --git a/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-using-batch-size.md b/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-using-batch-size.md new file mode 100644 index 00000000..97b9353c --- /dev/null +++ b/docs2/pages/ef-core-docs/documentations/batch-delete/scenarios/ef-core-batch-delete-using-batch-size.md @@ -0,0 +1,27 @@ +--- +Permalink: ef-core-batch-delete-using-batch-size +--- + +# Batch Size + +## Problem + +You need to delete millions of records and need to use a batch size to increase performance. + +## Solution + +The **BatchSize** property sets the amount of rows to delete in a single batch. + +Default Value = 4000 + + +{% include template-example.html %} +```csharp + +// using Z.EntityFramework.Plus; // Don't forget to include this. +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .Delete(x => x.BatchSize = 1000); + +``` +[Try it](https://dotnetfiddle.net/CpzGUz) diff --git a/docs2/pages/ef-core-docs/documentations/batch-update/ef-core-batch-update.md b/docs2/pages/ef-core-docs/documentations/batch-update/ef-core-batch-update.md new file mode 100644 index 00000000..7f31bf28 --- /dev/null +++ b/docs2/pages/ef-core-docs/documentations/batch-update/ef-core-batch-update.md @@ -0,0 +1,60 @@ +--- +Permalink: ef-core-batch-update +--- + +# Batch Update + +> 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. + +## Introduction + +Updating using Entity Framework Core 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. + +**EF+ Batch Update** updates multiple rows using an expression in a single database roundtrip and without loading entities in the context. + +{% include template-example.html %} +```csharp + +// using Z.EntityFramework.Plus; // Don't forget to include this. + +// UPDATE all users inactive for 2 years +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .Update(x => new User() { IsSoftDeleted = 1 }); + +``` +[Try it](https://dotnetfiddle.net/0CBNK1) + +## Limitations + + - **DO NOT** support Complex Type + - **DO NOT** support TPC + - **DO NOT** support TPH + - **DO NOT** support TPT + + If you need to use one of this feature, you need to use the library [Entity Framework Extensions](https://entityframework-extensions.net/) + + ### EF Core & Client Evaluation + + _Do not use this feature if Client Evaluation is enabled_ + +`Batch Update` use the SQL generated by EF Core. When a filter is made on client-side, it means the filtering happens in the application and not in the SQL executed. + +In other words, even if you put a filter, all rows tables could be potentially updated if the filter is made on the client-side. + +We always recommend to [disable the client evaluation](https://docs.microsoft.com/en-us/ef/core/querying/client-eval#optional-behavior-throw-an-exception-for-client-evaluation) to avoid performance issue in your application. + + +## Requirements + +- **EF+ Batch Delete:** Full version or Standalone version +- **Entity Framework Version:** EFCore +- **Minimum Framework Version:** .NET Framework 4 + +## Conclusion + +**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. + +Need help getting started? [info@zzzprojects.com](mailto:info@zzzprojects.com) + +We welcome all comments, ideas and suggestions to improve our library. diff --git a/docs2/pages/ef-docs/documentations/ef6-audit.md b/docs2/pages/ef-docs/documentations/audit/ef6-audit.md similarity index 99% rename from docs2/pages/ef-docs/documentations/ef6-audit.md rename to docs2/pages/ef-docs/documentations/audit/ef6-audit.md index f4d2a2e3..a661405d 100644 --- a/docs2/pages/ef-docs/documentations/ef6-audit.md +++ b/docs2/pages/ef-docs/documentations/audit/ef6-audit.md @@ -1,3 +1,7 @@ +--- +Permalink: audit +--- + # Audit ## Introduction diff --git a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-autosave.md b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-autosave.md similarity index 99% rename from docs2/pages/ef-docs/documentations/scenarios/ef6-audit-autosave.md rename to docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-autosave.md index 9ff7e7d3..eaded844 100644 --- a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-autosave.md +++ b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-autosave.md @@ -1,3 +1,7 @@ +--- +Permalink: ef6-audit-autosave +--- + # AutoSave Audit ## Problem diff --git a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-customization.md b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-customization.md similarity index 98% rename from docs2/pages/ef-docs/documentations/scenarios/ef6-audit-customization.md rename to docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-customization.md index a38f18ab..e94265fd 100644 --- a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-customization.md +++ b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-customization.md @@ -1,3 +1,7 @@ +--- +Permalink: ef6-audit-customization +--- + # Audit Customization ## Problem diff --git a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-data-annotations.md b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-data-annotations.md similarity index 94% rename from docs2/pages/ef-docs/documentations/scenarios/ef6-audit-data-annotations.md rename to docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-data-annotations.md index 5ab2a6fa..7e7af692 100644 --- a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-data-annotations.md +++ b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-data-annotations.md @@ -1,3 +1,7 @@ +--- +Permalink: ef6-audit-data-annotations +--- + # Data Annotations ## Problem diff --git a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-ef-extensions.md b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-ef-extensions.md similarity index 96% rename from docs2/pages/ef-docs/documentations/scenarios/ef6-audit-ef-extensions.md rename to docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-ef-extensions.md index 76cf4371..c58c9594 100644 --- a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-ef-extensions.md +++ b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-ef-extensions.md @@ -1,3 +1,7 @@ +--- +Permalink: ef6-audit-ef-extensions +--- + # Audit + Entity Framework Extensions If you are using Entity Framework Extensions, it is still possible to use the EF+ Audit features. diff --git a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-exclude-include-entity.md b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-exclude-include-entity.md similarity index 94% rename from docs2/pages/ef-docs/documentations/scenarios/ef6-audit-exclude-include-entity.md rename to docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-exclude-include-entity.md index a329b4f2..eb205332 100644 --- a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-exclude-include-entity.md +++ b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-exclude-include-entity.md @@ -1,3 +1,7 @@ +--- +Permalink: ef6-audit-exclude-include-entity +--- + # Exclude & Include Entity ## Problem diff --git a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-exclude-include-property.md b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-exclude-include-property.md similarity index 96% rename from docs2/pages/ef-docs/documentations/scenarios/ef6-audit-exclude-include-property.md rename to docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-exclude-include-property.md index dac7f408..ef5309dc 100644 --- a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-exclude-include-property.md +++ b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-exclude-include-property.md @@ -1,3 +1,7 @@ +--- +Permalink: ef6-audit-exclude-include-property +--- + # Exclude & Include Property ## Problem diff --git a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-format-value.md b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-format-value.md similarity index 94% rename from docs2/pages/ef-docs/documentations/scenarios/ef6-audit-format-value.md rename to docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-format-value.md index cf247b9e..913b5843 100644 --- a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-format-value.md +++ b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-format-value.md @@ -1,3 +1,7 @@ +--- +Permalink: ef6-audit-format-value +--- + # Format Value ## Problem diff --git a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-ignore-events.md b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-ignore-events.md similarity index 94% rename from docs2/pages/ef-docs/documentations/scenarios/ef6-audit-ignore-events.md rename to docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-ignore-events.md index acdcb2bf..e1e553ad 100644 --- a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-ignore-events.md +++ b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-ignore-events.md @@ -1,3 +1,7 @@ +--- +Permalink: ef-core-audit-ignore-events +--- + # Ignore Events ### Problem diff --git a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-property-unchanged.md b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-property-unchanged.md similarity index 93% rename from docs2/pages/ef-docs/documentations/scenarios/ef6-audit-property-unchanged.md rename to docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-property-unchanged.md index bc78b0a7..0c4d9764 100644 --- a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-property-unchanged.md +++ b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-property-unchanged.md @@ -1,3 +1,7 @@ +--- +Permalink: ef6-audit-property-unchanged +--- + # Property Unchanged ## Problem diff --git a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-retrieve-audit-entries-for-specific-item.md b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-retrieve-audit-entries-for-specific-item.md similarity index 95% rename from docs2/pages/ef-docs/documentations/scenarios/ef6-audit-retrieve-audit-entries-for-specific-item.md rename to docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-retrieve-audit-entries-for-specific-item.md index cd319d70..b8f4ad23 100644 --- a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-retrieve-audit-entries-for-specific-item.md +++ b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-retrieve-audit-entries-for-specific-item.md @@ -1,3 +1,7 @@ +--- +Permalink: ef6-audit-retrieve-audit-entries-for-specific-item +--- + # Retrieve AuditEntries for specific item ## Problem diff --git a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-soft-add-soft-delete.md b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-soft-add-soft-delete.md similarity index 94% rename from docs2/pages/ef-docs/documentations/scenarios/ef6-audit-soft-add-soft-delete.md rename to docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-soft-add-soft-delete.md index 79cf64ef..e7d38c1d 100644 --- a/docs2/pages/ef-docs/documentations/scenarios/ef6-audit-soft-add-soft-delete.md +++ b/docs2/pages/ef-docs/documentations/audit/scenarios/ef6-audit-soft-add-soft-delete.md @@ -1,3 +1,7 @@ +--- +Permalink: ef6-audit-soft-add-soft-delete +--- + # Soft Add & Soft Delete ## Problem diff --git a/docs2/pages/ef-docs/documentations/batch-delete/ef6-batch-delete.md b/docs2/pages/ef-docs/documentations/batch-delete/ef6-batch-delete.md new file mode 100644 index 00000000..08cd424b --- /dev/null +++ b/docs2/pages/ef-docs/documentations/batch-delete/ef6-batch-delete.md @@ -0,0 +1,60 @@ +--- +Permalink: batch-delete +--- + +# Batch Delete + +> This feature is now available on [Entity Framework Classic - Delete from Query](http://entityframework-classic.net/delete-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. + +## Introduction + +Deleting using Entity Framework can be very slow if you need to delete hundreds or thousands of entities. Entities are first loaded in the context before being deleted which is very bad for the performance and then, they are deleted one by one which makes the delete operation even worse. + +**EF+ Batch Delete** deletes multiple rows in a single database roundtrip and without loading entities in the context. + +{% include template-example.html %} +```csharp +// using Z.EntityFramework.Plus; // Don't forget to include this. + +// DELETE all users inactive for 2 years +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .Delete(); + +// DELETE using a BatchSize +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .Delete(x => x.BatchSize = 1000); + +``` +[Try it](https://dotnetfiddle.net/R6D5BX) + +## Scenarios + + - [Query Criteria](scenarios/ef6-batch-delete-query-criteria.md) + - [Batch Size](scenarios/ef6-batch-delete-using-batch-size.md) + - [Batch Delay Interval](scenarios/ef6-batch-delete-using-batch-delay-interval.md) + - [Executing Interceptor](scenarios/ef6-batch-delete-executing-interceptor.md) + +## Limitations + + - **DO NOT** support Complex Type + - **DO NOT** support TPC + - **DO NOT** support TPH + - **DO NOT** support TPT + +If you need to use one of this feature, you need to use the library [Entity Framework Extensions](https://entityframework-extensions.net/) + +## Requirements + +- **EF+ Batch Delete:** Full version or Standalone version +- **Entity Framework Version:** EF5, EF6 +- **Minimum Framework Version:** .NET Framework 4 + +## Conclusion + +**EF+ Batch Delete** is the most efficient way to delete records. 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 one for every record. + +Need help getting started? [info@zzzprojects.com](mailto:info@zzzprojects.com) + +We welcome all comments, ideas and suggestions to improve our library. diff --git a/docs2/pages/ef-docs/documentations/batch-delete/scenarios/ef6-batch-delete-executing-interceptor.md b/docs2/pages/ef-docs/documentations/batch-delete/scenarios/ef6-batch-delete-executing-interceptor.md new file mode 100644 index 00000000..1ba250d7 --- /dev/null +++ b/docs2/pages/ef-docs/documentations/batch-delete/scenarios/ef6-batch-delete-executing-interceptor.md @@ -0,0 +1,27 @@ +--- +Permalink: ef6-batch-delete-executing-interceptor +--- + +# Executing Interceptor + +### Problem + +You need to log the DbCommand information or change the CommandText, Connection or Transaction before the batch is executed. + +### Solution + +The **Executing** property intercepts the DbCommand with an action before being executed. + + +{% include template-example.html %} +```csharp + +// using Z.EntityFramework.Plus; // Don't forget to include this. + +string commandText +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .Delete(x => { x.Executing = command => commandText = command.CommandText; }); + +``` +[Try it](https://dotnetfiddle.net/VOEdOD) diff --git a/docs2/pages/ef-docs/documentations/batch-delete/scenarios/ef6-batch-delete-query-criteria.md b/docs2/pages/ef-docs/documentations/batch-delete/scenarios/ef6-batch-delete-query-criteria.md new file mode 100644 index 00000000..10afbb47 --- /dev/null +++ b/docs2/pages/ef-docs/documentations/batch-delete/scenarios/ef6-batch-delete-query-criteria.md @@ -0,0 +1,55 @@ +--- +Permalink: ef6-batch-delete-query-criteria +--- + +# Batch Delete using Query Criteria + +### Problem + +You need to delete one or millions of records based on a query criteria. + +### Solution + +The **Delete** IQueryable extension methods deletes rows matching the query criteria without loading entities in the context. + +{% include template-example.html %} +```csharp + +// using Z.EntityFramework.Plus; // Don't forget to include this. + +// DELETE all users +ctx.Users.Delete(); + +// DELETE all users inactive for 2 years +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .Delete(); + +``` +[Try it](https://dotnetfiddle.net/DTWmh1) + +## Batch DeleteAsync + +### Problem + +You need to delete one or millions of records based on a query criteria asynchronously. + +### Solution + +The **DeleteAsync** IQueryable extension methods deletes asynchronously rows matching the query criteria without loading entities in the context. + +{% include template-example.html %} +```csharp + +// using Z.EntityFramework.Plus; // Don't forget to include this. + +// DELETE all users +ctx.Users.DeleteAsync(); + +// DELETE all users inactive for 2 years +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .DeleteAsync(); + +``` +[Try it](https://dotnetfiddle.net/KUHvru) diff --git a/docs2/pages/ef-docs/documentations/batch-delete/scenarios/ef6-batch-delete-using-batch-delay-interval.md b/docs2/pages/ef-docs/documentations/batch-delete/scenarios/ef6-batch-delete-using-batch-delay-interval.md new file mode 100644 index 00000000..0cfac002 --- /dev/null +++ b/docs2/pages/ef-docs/documentations/batch-delete/scenarios/ef6-batch-delete-using-batch-delay-interval.md @@ -0,0 +1,28 @@ +--- +Permalink: ef6-batch-delete-using-batch-delay-interval +--- + +# Batch Delay Interval + +### Problem + +You need to delete millions of records but also need to pause between batches to let other applications keep on performing their CRUD operations. + +### Solution + +The **BatchDelayInterval** property sets the amount of time (in milliseconds) to wait before starting the next delete batch. + +Default Value = 0 + +{% include template-example.html %} +```csharp + +// using Z.EntityFramework.Plus; // Don't forget to include this. + +// Pause 2 seconds between every batch +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .Delete(x => x.BatchDelayInterval = 2000); + +``` +[Try it](https://dotnetfiddle.net/to4sjm) diff --git a/docs2/pages/ef-docs/documentations/batch-delete/scenarios/ef6-batch-delete-using-batch-size.md b/docs2/pages/ef-docs/documentations/batch-delete/scenarios/ef6-batch-delete-using-batch-size.md new file mode 100644 index 00000000..b4e718a3 --- /dev/null +++ b/docs2/pages/ef-docs/documentations/batch-delete/scenarios/ef6-batch-delete-using-batch-size.md @@ -0,0 +1,27 @@ +--- +Permalink: ef6-batch-delete-using-batch-size +--- + +# Batch Size + +## Problem + +You need to delete millions of records and need to use a batch size to increase performance. + +## Solution + +The **BatchSize** property sets the amount of rows to delete in a single batch. + +Default Value = 4000 + + +{% include template-example.html %} +```csharp + +// using Z.EntityFramework.Plus; // Don't forget to include this. +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .Delete(x => x.BatchSize = 1000); + +``` +[Try it](https://dotnetfiddle.net/c6TLU3) diff --git a/docs2/pages/ef-docs/documentations/batch-update/ef6-batch-update.md b/docs2/pages/ef-docs/documentations/batch-update/ef6-batch-update.md new file mode 100644 index 00000000..6d88a641 --- /dev/null +++ b/docs2/pages/ef-docs/documentations/batch-update/ef6-batch-update.md @@ -0,0 +1,54 @@ +--- +Permalink: batch-update +--- + +# Batch Update + +> 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. + +## Introduction + +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. + +**EF+ Batch Update** updates multiple rows using an expression in a single database roundtrip and without loading entities in the context. + +{% include template-example.html %} +```csharp + +// using Z.EntityFramework.Plus; // Don't forget to include this. + +// UPDATE all users inactive for 2 years +var date = DateTime.Now.AddYears(-2); +ctx.Users.Where(x => x.LastLoginDate < date) + .Update(x => new User() { IsSoftDeleted = 1 }); + +``` +[Try it](https://dotnetfiddle.net/uzsdub) + +## Scenarios + + - [Query Criteria](scenarios/ef6-batch-update-query-criteria.md) + - [Executing Interceptor](scenarios/ef6-batch-update-executing-interceptor.md) + +## Limitations + + - **DO NOT** support Complex Type + - **DO NOT** support TPC + - **DO NOT** support TPH + - **DO NOT** support TPT + +If you need to use one of this feature, you need to use the library [Entity Framework Extensions](https://entityframework-extensions.net/) + +## Requirements + +- **EF+ Batch Delete:** Full version or Standalone version +- **Entity Framework Version:** EF5, EF6 +- **Minimum Framework Version:** .NET Framework 4 + +## Conclusion + +**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. + +Need help getting started? [info@zzzprojects.com](mailto:info@zzzprojects.com) + +We welcome all comments, ideas and suggestions to improve our library.