Skip to content

Commit

Permalink
Sproc fixes (#28942)
Browse files Browse the repository at this point in the history
* Don't attempt to propagate rows affected result columns.
* Warn if an unexpected trailing result set is found.
* Throw an informative message if a result set is missing.

Fixes #28803
  • Loading branch information
roji committed Sep 1, 2022
1 parent 5d86648 commit d7d6d91
Show file tree
Hide file tree
Showing 12 changed files with 315 additions and 109 deletions.
15 changes: 14 additions & 1 deletion src/EFCore.Relational/Diagnostics/RelationalEventId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ private enum Id
BatchSmallerThanMinBatchSize,
BatchExecutorFailedToRollbackToSavepoint,
BatchExecutorFailedToReleaseSavepoint,
OptionalDependentWithAllNullPropertiesWarning
OptionalDependentWithAllNullPropertiesWarning,
UnexpectedTrailingResultSetWhenSaving,
}

private static readonly string _connectionPrefix = DbLoggerCategory.Database.Connection.Name + ".";
Expand Down Expand Up @@ -1001,4 +1002,16 @@ private static EventId MakeUpdateId(Id id)
/// </remarks>
public static readonly EventId OptionalDependentWithAllNullPropertiesWarning
= MakeUpdateId(Id.OptionalDependentWithAllNullPropertiesWarning);

/// <summary>
/// An unexpected trailing result set was found when reading the results of a SaveChanges operation; this may indicate that a stored
/// procedure returned a result set without being configured for it in the EF model. Check your stored procedure definitions.
/// </summary>
/// <remarks>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Update" /> category.
/// </para>
/// </remarks>
public static readonly EventId UnexpectedTrailingResultSetWhenSaving =
MakeUpdateId(Id.UnexpectedTrailingResultSetWhenSaving);
}
27 changes: 27 additions & 0 deletions src/EFCore.Relational/Diagnostics/RelationalLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3327,4 +3327,31 @@ private static string ColumnOrderIgnoredWarning(EventDefinitionBase definition,
var p = (MigrationColumnOperationEventData)payload;
return d.GenerateMessage((p.ColumnOperation.Table, p.ColumnOperation.Schema).FormatTable(), p.ColumnOperation.Name);
}

/// <summary>
/// Logs for the <see cref="RelationalEventId.UnexpectedTrailingResultSetWhenSaving" /> event.
/// </summary>
/// <param name="diagnostics">The diagnostics logger to use.</param>
public static void UnexpectedTrailingResultSetWhenSaving(this IDiagnosticsLogger<DbLoggerCategory.Update> diagnostics)
{
var definition = RelationalResources.LogUnexpectedTrailingResultSetWhenSaving(diagnostics);

if (diagnostics.ShouldLog(definition))
{
definition.Log(diagnostics);
}

if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
{
var eventData = new EventData(
definition,
static (definition, _) =>
{
var d = (EventDefinition)definition;
return d.GenerateMessage();
});

diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,13 @@ public abstract class RelationalLoggingDefinitions : LoggingDefinitions
/// </summary>
[EntityFrameworkInternal]
public EventDefinitionBase? LogExceptionDuringExecuteUpdate;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[EntityFrameworkInternal]
public EventDefinitionBase? LogUnexpectedTrailingResultSetWhenSaving;
}
31 changes: 31 additions & 0 deletions src/EFCore.Relational/Properties/RelationalStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/EFCore.Relational/Properties/RelationalStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,10 @@
<value>An error occurred using a transaction.</value>
<comment>Error RelationalEventId.TransactionError</comment>
</data>
<data name="LogUnexpectedTrailingResultSetWhenSaving" xml:space="preserve">
<value>An unexpected trailing result set was found when reading the results of a SaveChanges operation; this may indicate that a stored procedure returned a result set without being configured for it in the EF model. Check your stored procedure definitions.</value>
<comment>Warning CoreEventId.UnexpectedTrailingResultSetWhenSaving</comment>
</data>
<data name="LogUnnamedIndexAllPropertiesNotToMappedToAnyTable" xml:space="preserve">
<value>The unnamed index on the entity type '{entityType}' specifies properties {indexProperties}, but none of these properties are mapped to a column in any table. This index will not be created in the database.</value>
<comment>Warning RelationalEventId.AllIndexPropertiesNotToMappedToAnyTable string string</comment>
Expand Down Expand Up @@ -855,6 +859,9 @@
<data name="MissingParameterValue" xml:space="preserve">
<value>No value was provided for the required parameter '{parameter}'.</value>
</data>
<data name="MissingResultSetWhenSaving" xml:space="preserve">
<value>A result set was was missing when reading the results of a SaveChanges operation; this may indicate that a stored procedure was configured to return results in the EF model, but did not. Check your stored procedure definitions.</value>
</data>
<data name="ModificationCommandBatchAlreadyComplete" xml:space="preserve">
<value>Cannot add commands to a completed ModificationCommandBatch.</value>
</data>
Expand Down
Loading

0 comments on commit d7d6d91

Please sign in to comment.