Skip to content

Commit 968eff6

Browse files
committed
Adds DbContext to CommandEventData
Fixes #16159 Also introduced a parameter object for the `RelationalCommand` execution methods. This will make it easier to pass new things here without making a breaking change. Did a little refactoring to simplify the code in `RelationalCommand` and avoid a couple of places where we were allocating.
1 parent 1c14b58 commit 968eff6

File tree

38 files changed

+1000
-637
lines changed

38 files changed

+1000
-637
lines changed

src/EFCore.Relational/Diagnostics/CommandEndEventData.cs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,38 @@ public class CommandEndEventData : CommandEventData
1919
/// </summary>
2020
/// <param name="eventDefinition"> The event definition. </param>
2121
/// <param name="messageGenerator"> A delegate that generates a log message for this event. </param>
22-
/// <param name="command">
23-
/// The <see cref="DbCommand" />.
24-
/// </param>
25-
/// <param name="executeMethod">
26-
/// The <see cref="DbCommand" /> method.
27-
/// </param>
28-
/// <param name="commandId">
29-
/// A correlation ID that identifies the <see cref="DbCommand" /> instance being used.
30-
/// </param>
31-
/// <param name="connectionId">
32-
/// A correlation ID that identifies the <see cref="DbConnection" /> instance being used.
33-
/// </param>
34-
/// <param name="async">
35-
/// Indicates whether or not the command was executed asynchronously.
36-
/// </param>
37-
/// <param name="logParameterValues">
38-
/// Indicates whether or not the application allows logging of parameter values.
39-
/// </param>
40-
/// <param name="startTime">
41-
/// The start time of this event.
42-
/// </param>
43-
/// <param name="duration">
44-
/// The duration this event.
45-
/// </param>
22+
/// <param name="command"> The <see cref="DbCommand" />. </param>
23+
/// <param name="context"> The <see cref="DbContext" /> currently being used, ot null if not known. </param>
24+
/// <param name="executeMethod"> The <see cref="DbCommand" /> method. </param>
25+
/// <param name="commandId"> A correlation ID that identifies the <see cref="DbCommand" /> instance being used. </param>
26+
/// <param name="connectionId"> A correlation ID that identifies the <see cref="DbConnection" /> instance being used. </param>
27+
/// <param name="async"> Indicates whether or not the command was executed asynchronously. </param>
28+
/// <param name="logParameterValues"> Indicates whether or not the application allows logging of parameter values. </param>
29+
/// <param name="startTime"> The start time of this event. </param>
30+
/// <param name="duration"> The duration this event. </param>
4631
public CommandEndEventData(
4732
[NotNull] EventDefinitionBase eventDefinition,
4833
[NotNull] Func<EventDefinitionBase, EventData, string> messageGenerator,
4934
[NotNull] DbCommand command,
35+
[CanBeNull] DbContext context,
5036
DbCommandMethod executeMethod,
5137
Guid commandId,
5238
Guid connectionId,
5339
bool async,
5440
bool logParameterValues,
5541
DateTimeOffset startTime,
5642
TimeSpan duration)
57-
: base(eventDefinition, messageGenerator, command, executeMethod, commandId, connectionId, async, logParameterValues, startTime)
43+
: base(
44+
eventDefinition,
45+
messageGenerator,
46+
command,
47+
context,
48+
executeMethod,
49+
commandId,
50+
connectionId,
51+
async,
52+
logParameterValues,
53+
startTime)
5854
=> Duration = duration;
5955

6056
/// <summary>

src/EFCore.Relational/Diagnostics/CommandErrorEventData.cs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,21 @@ public class CommandErrorEventData : CommandEndEventData, IErrorEventData
1818
/// </summary>
1919
/// <param name="eventDefinition"> The event definition. </param>
2020
/// <param name="messageGenerator"> A delegate that generates a log message for this event. </param>
21-
/// <param name="command">
22-
/// The <see cref="DbCommand" /> that was executing when it failed.
23-
/// </param>
24-
/// <param name="executeMethod">
25-
/// The <see cref="DbCommand" /> method that was used to execute the command.
26-
/// </param>
27-
/// <param name="commandId">
28-
/// A correlation ID that identifies the <see cref="DbCommand" /> instance being used.
29-
/// </param>
30-
/// <param name="connectionId">
31-
/// A correlation ID that identifies the <see cref="DbConnection" /> instance being used.
32-
/// </param>
33-
/// <param name="exception">
34-
/// The exception that was thrown when execution failed.
35-
/// </param>
36-
/// <param name="async">
37-
/// Indicates whether or not the command was executed asynchronously.
38-
/// </param>
39-
/// <param name="logParameterValues">
40-
/// Indicates whether or not the application allows logging of parameter values.
41-
/// </param>
42-
/// <param name="startTime">
43-
/// The start time of this event.
44-
/// </param>
45-
/// <param name="duration">
46-
/// The duration this event.
47-
/// </param>
21+
/// <param name="command"> The <see cref="DbCommand" /> that was executing when it failed. </param>
22+
/// <param name="context"> The <see cref="DbContext" /> currently being used, ot null if not known. </param>
23+
/// <param name="executeMethod"> The <see cref="DbCommand" /> method that was used to execute the command. </param>
24+
/// <param name="commandId"> A correlation ID that identifies the <see cref="DbCommand" /> instance being used. </param>
25+
/// <param name="connectionId"> A correlation ID that identifies the <see cref="DbConnection" /> instance being used. </param>
26+
/// <param name="exception"> The exception that was thrown when execution failed. </param>
27+
/// <param name="async"> Indicates whether or not the command was executed asynchronously. </param>
28+
/// <param name="logParameterValues"> Indicates whether or not the application allows logging of parameter values. </param>
29+
/// <param name="startTime"> The start time of this event. </param>
30+
/// <param name="duration"> The duration this event. </param>
4831
public CommandErrorEventData(
4932
[NotNull] EventDefinitionBase eventDefinition,
5033
[NotNull] Func<EventDefinitionBase, EventData, string> messageGenerator,
5134
[NotNull] DbCommand command,
35+
[CanBeNull] DbContext context,
5236
DbCommandMethod executeMethod,
5337
Guid commandId,
5438
Guid connectionId,
@@ -57,7 +41,18 @@ public CommandErrorEventData(
5741
bool logParameterValues,
5842
DateTimeOffset startTime,
5943
TimeSpan duration)
60-
: base(eventDefinition, messageGenerator, command, executeMethod, commandId, connectionId, async, logParameterValues, startTime, duration)
44+
: base(
45+
eventDefinition,
46+
messageGenerator,
47+
command,
48+
context,
49+
executeMethod,
50+
commandId,
51+
connectionId,
52+
async,
53+
logParameterValues,
54+
startTime,
55+
duration)
6156
=> Exception = exception;
6257

6358
/// <summary>

src/EFCore.Relational/Diagnostics/CommandEventData.cs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,33 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics
1212
/// The <see cref="DiagnosticSource" /> event payload for
1313
/// <see cref="RelationalEventId" /> command events.
1414
/// </summary>
15-
public class CommandEventData : EventData
15+
public class CommandEventData : DbContextEventData
1616
{
1717
/// <summary>
1818
/// Constructs the event payload.
1919
/// </summary>
2020
/// <param name="eventDefinition"> The event definition. </param>
2121
/// <param name="messageGenerator"> A delegate that generates a log message for this event. </param>
22-
/// <param name="command">
23-
/// The <see cref="DbCommand" />.
24-
/// </param>
25-
/// <param name="executeMethod">
26-
/// The <see cref="DbCommand" /> method.
27-
/// </param>
28-
/// <param name="commandId">
29-
/// A correlation ID that identifies the <see cref="DbCommand" /> instance being used.
30-
/// </param>
31-
/// <param name="connectionId">
32-
/// A correlation ID that identifies the <see cref="DbConnection" /> instance being used.
33-
/// </param>
34-
/// <param name="async">
35-
/// Indicates whether or not the command was executed asynchronously.
36-
/// </param>
37-
/// <param name="logParameterValues">
38-
/// Indicates whether or not the application allows logging of parameter values.
39-
/// </param>
40-
/// <param name="startTime">
41-
/// The start time of this event.
42-
/// </param>
22+
/// <param name="command"> The <see cref="DbCommand" />. </param>
23+
/// <param name="context"> The <see cref="DbContext" /> currently being used, ot null if not known. </param>
24+
/// <param name="executeMethod"> The <see cref="DbCommand" /> method. </param>
25+
/// <param name="commandId"> A correlation ID that identifies the <see cref="DbCommand" /> instance being used. </param>
26+
/// <param name="connectionId"> A correlation ID that identifies the <see cref="DbConnection" /> instance being used. </param>
27+
/// <param name="async"> Indicates whether or not the command was executed asynchronously. </param>
28+
/// <param name="logParameterValues"> Indicates whether or not the application allows logging of parameter values. </param>
29+
/// <param name="startTime"> The start time of this event. </param>
4330
public CommandEventData(
4431
[NotNull] EventDefinitionBase eventDefinition,
4532
[NotNull] Func<EventDefinitionBase, EventData, string> messageGenerator,
4633
[NotNull] DbCommand command,
34+
[CanBeNull] DbContext context,
4735
DbCommandMethod executeMethod,
4836
Guid commandId,
4937
Guid connectionId,
5038
bool async,
5139
bool logParameterValues,
5240
DateTimeOffset startTime)
53-
: base(eventDefinition, messageGenerator)
41+
: base(eventDefinition, messageGenerator, context)
5442
{
5543
Command = command;
5644
CommandId = commandId;

src/EFCore.Relational/Diagnostics/CommandExecutedEventData.cs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,21 @@ public class CommandExecutedEventData : CommandEndEventData
1818
/// </summary>
1919
/// <param name="eventDefinition"> The event definition. </param>
2020
/// <param name="messageGenerator"> A delegate that generates a log message for this event. </param>
21-
/// <param name="command">
22-
/// The <see cref="DbCommand" /> that was executing when it failed.
23-
/// </param>
24-
/// <param name="executeMethod">
25-
/// The <see cref="DbCommand" /> method that was used to execute the command.
26-
/// </param>
27-
/// <param name="commandId">
28-
/// A correlation ID that identifies the <see cref="DbCommand" /> instance being used.
29-
/// </param>
30-
/// <param name="connectionId">
31-
/// A correlation ID that identifies the <see cref="DbConnection" /> instance being used.
32-
/// </param>
33-
/// <param name="result">
34-
/// The result of executing the operation.
35-
/// </param>
36-
/// <param name="async">
37-
/// Indicates whether or not the command was executed asynchronously.
38-
/// </param>
39-
/// <param name="logParameterValues">
40-
/// Indicates whether or not the application allows logging of parameter values.
41-
/// </param>
42-
/// <param name="startTime">
43-
/// The start time of this event.
44-
/// </param>
45-
/// <param name="duration">
46-
/// The duration this event.
47-
/// </param>
21+
/// <param name="command"> The <see cref="DbCommand" /> that was executing when it failed. </param>
22+
/// <param name="context"> The <see cref="DbContext" /> currently being used, ot null if not known. </param>
23+
/// <param name="executeMethod"> The <see cref="DbCommand" /> method that was used to execute the command. </param>
24+
/// <param name="commandId"> A correlation ID that identifies the <see cref="DbCommand" /> instance being used. </param>
25+
/// <param name="connectionId"> A correlation ID that identifies the <see cref="DbConnection" /> instance being used. </param>
26+
/// <param name="result"> The result of executing the operation. </param>
27+
/// <param name="async"> Indicates whether or not the command was executed asynchronously. </param>
28+
/// <param name="logParameterValues"> Indicates whether or not the application allows logging of parameter values. </param>
29+
/// <param name="startTime"> The start time of this event. </param>
30+
/// <param name="duration"> The duration this event. </param>
4831
public CommandExecutedEventData(
4932
[NotNull] EventDefinitionBase eventDefinition,
5033
[NotNull] Func<EventDefinitionBase, EventData, string> messageGenerator,
5134
[NotNull] DbCommand command,
35+
[CanBeNull] DbContext context,
5236
DbCommandMethod executeMethod,
5337
Guid commandId,
5438
Guid connectionId,
@@ -57,7 +41,18 @@ public CommandExecutedEventData(
5741
bool logParameterValues,
5842
DateTimeOffset startTime,
5943
TimeSpan duration)
60-
: base(eventDefinition, messageGenerator, command, executeMethod, commandId, connectionId, async, logParameterValues, startTime, duration)
44+
: base(
45+
eventDefinition,
46+
messageGenerator,
47+
command,
48+
context,
49+
executeMethod,
50+
commandId,
51+
connectionId,
52+
async,
53+
logParameterValues,
54+
startTime,
55+
duration)
6156
=> Result = result;
6257

6358
/// <summary>

0 commit comments

Comments
 (0)