Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
604 changes: 602 additions & 2 deletions entity-framework/core/logging-events-diagnostics/interceptors.md

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions entity-framework/core/what-is-new/ef-core-6.0/whatsnew.md
Original file line number Diff line number Diff line change
Expand Up @@ -3428,9 +3428,9 @@ This validation can be disabled if necessary. For example:

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

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`:
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`:

<!--
```csharp
public class CommandSourceInterceptor : DbCommandInterceptor
{
public override InterceptionResult<DbDataReader> ReaderExecuting(
Expand All @@ -3446,8 +3446,7 @@ public class CommandSourceInterceptor : DbCommandInterceptor
return result;
}
}
-->
[!code-csharp[Interceptor](../../../../samples/core/Miscellaneous/NewInEFCore6/CommandSourceSample.cs?name=Interceptor)]
```

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

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

For more information, see [Filtering by command source](xref:core/logging-events-diagnostics/interceptors#filtering-by-command-source).

### Better temporary values handling

GitHub Issue: [#24245](https://github.com/dotnet/efcore/issues/24245).
Expand Down
535 changes: 57 additions & 478 deletions entity-framework/core/what-is-new/ef-core-7.0/whatsnew.md

Large diffs are not rendered by default.

71 changes: 0 additions & 71 deletions samples/core/Miscellaneous/NewInEFCore6/CommandSourceSample.cs

This file was deleted.

1 change: 0 additions & 1 deletion samples/core/Miscellaneous/NewInEFCore6/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public static async Task Main()
await HasConversionSample.Can_set_value_converter_type_using_generic_method();
MinimalApiSample.Add_a_DbContext_and_provider();
await ToInMemoryQuerySample.Can_query_keyless_types_from_in_memory_database();
await CommandSourceSample.Interceptors_get_the_source_of_the_command();
await ScaffoldingSample.Reverse_engineer_from_database();
await ManyToManyConfigurationSample.Many_to_many_relationships_may_need_less_configuration();
await ConvertNullsSample.Value_converters_can_convert_nulls();
Expand Down
113 changes: 0 additions & 113 deletions samples/core/Miscellaneous/NewInEFCore7/InjectLoggerSample.cs

This file was deleted.

119 changes: 0 additions & 119 deletions samples/core/Miscellaneous/NewInEFCore7/LazyConnectionStringSample.cs

This file was deleted.

Loading
Loading