Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
f31fe29
Merge pull request #2 from zzzprojects/master
waqasm78 Sep 17, 2019
2eee00f
Update ef-core-audit.md
waqasm78 Sep 17, 2019
02aa3ec
Update ef6-audit.md
waqasm78 Sep 17, 2019
3a11582
Update ef6-audit-autosave.md
waqasm78 Sep 17, 2019
56af352
Update ef6-audit-customization.md
waqasm78 Sep 17, 2019
8892e90
Update ef6-audit-data-annotations.md
waqasm78 Sep 17, 2019
b7a3dd1
Update ef6-audit-ef-extensions.md
waqasm78 Sep 17, 2019
83c31f5
Update ef6-audit-exclude-include-entity.md
waqasm78 Sep 17, 2019
50ab153
Update ef6-audit-exclude-include-property.md
waqasm78 Sep 17, 2019
946ed4a
Update ef6-audit-format-value.md
waqasm78 Sep 17, 2019
97c526b
Update ef-core-audit-ef-extensions.md
waqasm78 Sep 17, 2019
0b455b3
Update ef6-audit-ignore-events.md
waqasm78 Sep 17, 2019
48872b8
Update ef6-audit-property-unchanged.md
waqasm78 Sep 17, 2019
f3c7629
Update ef6-audit-retrieve-audit-entries-for-specific-item.md
waqasm78 Sep 17, 2019
0c393e5
Update ef6-audit-soft-add-soft-delete.md
waqasm78 Sep 17, 2019
4a0ea11
Update ef-core-audit-autosave.md
waqasm78 Sep 17, 2019
ebf8c14
Update ef-core-audit-autosave.md
waqasm78 Sep 17, 2019
5047d9f
Update ef-core-audit-customization.md
waqasm78 Sep 17, 2019
103e1ef
Update ef-core-audit-data-annotations.md
waqasm78 Sep 17, 2019
8bc43dc
Update ef-core-audit-exclude-include-entity.md
waqasm78 Sep 17, 2019
7c88889
Update ef-core-audit-exclude-include-property.md
waqasm78 Sep 17, 2019
11c3591
Update ef-core-audit-format-value.md
waqasm78 Sep 17, 2019
a7f3070
Update ef-core-audit-ignore-events.md
waqasm78 Sep 17, 2019
3984a4f
Update ef-core-audit-property-unchanged.md
waqasm78 Sep 17, 2019
85ae05b
Update ef-core-audit-retrieve-audit-entries-for-specific-item.md
waqasm78 Sep 17, 2019
fcdfec6
Update ef-core-audit-soft-add-soft-delete.md
waqasm78 Sep 17, 2019
fdc1272
Rename docs2/pages/ef-docs/documentations/ef6-audit.md to docs2/pages…
waqasm78 Sep 17, 2019
7c12003
Rename docs2/pages/ef-docs/documentations/scenarios/ef6-audit-autosav…
waqasm78 Sep 17, 2019
540210c
Rename docs2/pages/ef-docs/documentations/scenarios/audit/ef6-audit-a…
waqasm78 Sep 17, 2019
ef8a3fa
Rename docs2/pages/ef-docs/documentations/audit/ef6-audit-autosave.md…
waqasm78 Sep 17, 2019
f1fd6c4
Rename docs2/pages/ef-docs/documentations/scenarios/ef6-audit-customi…
waqasm78 Sep 17, 2019
7d0d3b0
Rename docs2/pages/ef-docs/documentations/scenarios/ef6-audit-data-an…
waqasm78 Sep 17, 2019
18ff050
Rename docs2/pages/ef-docs/documentations/scenarios/ef6-audit-ef-exte…
waqasm78 Sep 17, 2019
1244bff
Rename docs2/pages/ef-docs/documentations/scenarios/ef6-audit-exclude…
waqasm78 Sep 17, 2019
1c0fe5d
Rename docs2/pages/ef-docs/documentations/scenarios/ef6-audit-exclude…
waqasm78 Sep 17, 2019
56dc2b9
Rename docs2/pages/ef-docs/documentations/scenarios/ef6-audit-format-…
waqasm78 Sep 17, 2019
b6ade85
Rename docs2/pages/ef-docs/documentations/scenarios/ef6-audit-ignore-…
waqasm78 Sep 17, 2019
55217e5
Rename docs2/pages/ef-docs/documentations/scenarios/ef6-audit-propert…
waqasm78 Sep 17, 2019
ebb599a
Rename docs2/pages/ef-docs/documentations/scenarios/ef6-audit-retriev…
waqasm78 Sep 17, 2019
760e13e
Rename docs2/pages/ef-docs/documentations/scenarios/ef6-audit-soft-ad…
waqasm78 Sep 17, 2019
5ab28aa
Rename docs2/pages/ef-core-docs/documentations/ef-core-audit.md to do…
waqasm78 Sep 17, 2019
7f27a7f
Rename docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audi…
waqasm78 Sep 17, 2019
4ae5c83
Rename docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audi…
waqasm78 Sep 17, 2019
24c2fc0
Rename docs2/pages/ef-core-docs/documentations/scenarios/audit/scenar…
waqasm78 Sep 17, 2019
29cfd0e
Rename core-audit-autosave.md to ef-core-audit-autosave.md
waqasm78 Sep 17, 2019
f0cc6cb
Rename docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audi…
waqasm78 Sep 17, 2019
23c5d56
Rename docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audi…
waqasm78 Sep 17, 2019
fc8a059
Rename docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audi…
waqasm78 Sep 17, 2019
c88b798
Rename docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audi…
waqasm78 Sep 17, 2019
6dfbabd
Rename docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audi…
waqasm78 Sep 17, 2019
fa2feb1
Rename docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audi…
waqasm78 Sep 17, 2019
b88a075
Rename docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audi…
waqasm78 Sep 17, 2019
45d934e
Rename docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audi…
waqasm78 Sep 17, 2019
4e3d442
Rename docs2/pages/ef-core-docs/documentations/scenarios/ef-core-audi…
waqasm78 Sep 17, 2019
b8931c3
Create ef6-batch-delete.md
waqasm78 Sep 17, 2019
b56e55e
Create ef-core-batch-delete.md
waqasm78 Sep 17, 2019
ac942e2
Create ef-core-batch-delete-query-criteria.md
waqasm78 Sep 17, 2019
573cb49
Create ef6-batch-delete-query-criteria.md
waqasm78 Sep 17, 2019
4fbb912
Create ef-core-batch-delete-using-batch-size.md
waqasm78 Sep 17, 2019
35f4068
Create ef6-batch-delete-using-batch-size.md
waqasm78 Sep 17, 2019
00f6fbd
Create ef-core-batch-delete-using-batch-delay-interval.md
waqasm78 Sep 17, 2019
61bb62c
Create ef6-batch-delete-using-batch-delay-interval.md
waqasm78 Sep 17, 2019
a7e752d
Create ef-core-batch-delete-executing-interceptor.md
waqasm78 Sep 17, 2019
cfb5a87
Create ef6-batch-delete-executing-interceptor.md
waqasm78 Sep 17, 2019
eefab6d
Create ef-core-batch-delete-inmemory.md
waqasm78 Sep 17, 2019
ba79637
Update ef-core-batch-delete.md
waqasm78 Sep 17, 2019
88803cc
Update ef-core-batch-delete.md
waqasm78 Sep 17, 2019
42219df
Update ef6-batch-delete.md
waqasm78 Sep 17, 2019
c4054dd
Create ef-core-batch-update.md
waqasm78 Sep 18, 2019
764f9b3
Create ef6-batch-update.md
waqasm78 Sep 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
Permalink: ef-core-audit
---
# Audit

## Introduction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
Permalink: ef-core-audit-autosave
---

# AutoSave Audit

## Problem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
Permalink: ef-core-audit-customization
---

# Audit Customization

## Problem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
Permalink: ef-core-data-annotations
---

# Data Annotations

## Problem
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
Permalink: ef-core-audit-exclude-include-entity
---

# Exclude & Include Entity

## Problem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
Permalink: ef-core-audit-exclude-include-property
---

# Exclude & Include Property

## Problem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
Permalink: ef-core-audit-format-value
---

# Format Value

## Problem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
Permalink: ef-core-audit-ignore-events
---

# Ignore Events

### Problem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
Permalink: ef-core-audit-property-unchanged
---

# Property Unchanged

## Problem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
Permalink: ef-core-audit-retrieve-audit-entries-for-specific-item
---

# Retrieve AuditEntries for specific item

## Problem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
Permalink: ef-core-audit-soft-add-soft-delete
---

# Soft Add & Soft Delete

## Problem
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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();

```
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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.
Loading