Skip to content

Commit 2be33b1

Browse files
authored
Add missing documentation for interceptors (#5279)
Closes #4417 Closes #4726
1 parent f30c06e commit 2be33b1

11 files changed

Lines changed: 664 additions & 1161 deletions

File tree

entity-framework/core/logging-events-diagnostics/interceptors.md

Lines changed: 602 additions & 2 deletions
Large diffs are not rendered by default.

entity-framework/core/what-is-new/ef-core-6.0/whatsnew.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3428,9 +3428,9 @@ This validation can be disabled if necessary. For example:
34283428

34293429
GitHub Issue: [#23719](https://github.com/dotnet/efcore/issues/23719). This feature was contributed by [@Giorgi](https://github.com/Giorgi). Many thanks!
34303430

3431-
The `CommandEventData` supplied to diagnostics sources and interceptors now contains an enum value indicating which part of EF was responsible for creating the command. This can be used as a filter in the diagnostics or interceptor. For example, we may want an interceptor that only applies to commands that come from `SaveChanges`:
3431+
The <xref:Microsoft.EntityFrameworkCore.Diagnostics.CommandEventData> supplied to diagnostics sources and interceptors now contains a <xref:Microsoft.EntityFrameworkCore.Diagnostics.CommandSource> enum value indicating which part of EF was responsible for creating the command. This can be used to filter interceptor behavior, for example to only intercept commands originating from `SaveChanges`:
34323432

3433-
<!--
3433+
```csharp
34343434
public class CommandSourceInterceptor : DbCommandInterceptor
34353435
{
34363436
public override InterceptionResult<DbDataReader> ReaderExecuting(
@@ -3446,8 +3446,7 @@ public class CommandSourceInterceptor : DbCommandInterceptor
34463446
return result;
34473447
}
34483448
}
3449-
-->
3450-
[!code-csharp[Interceptor](../../../../samples/core/Miscellaneous/NewInEFCore6/CommandSourceSample.cs?name=Interceptor)]
3449+
```
34513450

34523451
This filters the interceptor to only `SaveChanges` events when used in an application which also generates migrations and queries. For example:
34533452

@@ -3462,6 +3461,8 @@ FROM [Customers]
34623461
WHERE @@ROWCOUNT = 1 AND [Id] = scope_identity();
34633462
```
34643463

3464+
For more information, see [Filtering by command source](xref:core/logging-events-diagnostics/interceptors#filtering-by-command-source).
3465+
34653466
### Better temporary values handling
34663467

34673468
GitHub Issue: [#24245](https://github.com/dotnet/efcore/issues/24245).

entity-framework/core/what-is-new/ef-core-7.0/whatsnew.md

Lines changed: 57 additions & 478 deletions
Large diffs are not rendered by default.

samples/core/Miscellaneous/NewInEFCore6/CommandSourceSample.cs

Lines changed: 0 additions & 71 deletions
This file was deleted.

samples/core/Miscellaneous/NewInEFCore6/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public static async Task Main()
4040
await HasConversionSample.Can_set_value_converter_type_using_generic_method();
4141
MinimalApiSample.Add_a_DbContext_and_provider();
4242
await ToInMemoryQuerySample.Can_query_keyless_types_from_in_memory_database();
43-
await CommandSourceSample.Interceptors_get_the_source_of_the_command();
4443
await ScaffoldingSample.Reverse_engineer_from_database();
4544
await ManyToManyConfigurationSample.Many_to_many_relationships_may_need_less_configuration();
4645
await ConvertNullsSample.Value_converters_can_convert_nulls();

samples/core/Miscellaneous/NewInEFCore7/InjectLoggerSample.cs

Lines changed: 0 additions & 113 deletions
This file was deleted.

samples/core/Miscellaneous/NewInEFCore7/LazyConnectionStringSample.cs

Lines changed: 0 additions & 119 deletions
This file was deleted.

0 commit comments

Comments
 (0)