Skip to content

Commit 9d706b5

Browse files
committed
Address review comments
1 parent 209bbbe commit 9d706b5

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

src/EFCore.Relational/Storage/RelationalTypeMapping.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,7 @@ public virtual DbParameter CreateParameter(
496496
parameter.Direction = direction;
497497
parameter.ParameterName = name;
498498

499-
var isInputParameter = direction is ParameterDirection.Input or ParameterDirection.InputOutput;
500-
501-
if (isInputParameter)
499+
if (direction.HasFlag(ParameterDirection.Input))
502500
{
503501
value = NormalizeEnumValue(value);
504502

@@ -512,7 +510,10 @@ public virtual DbParameter CreateParameter(
512510

513511
if (nullable.HasValue)
514512
{
515-
Check.DebugAssert(nullable.Value || !isInputParameter || value != null, "Null value in a non-nullable input parameter");
513+
Check.DebugAssert(nullable.Value
514+
|| !direction.HasFlag(ParameterDirection.Input)
515+
|| value != null,
516+
"Null value in a non-nullable input parameter");
516517

517518
parameter.IsNullable = nullable.Value;
518519
}

src/EFCore.Relational/Update/AffectedCountModificationCommandBatch.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void HandleOutputParameters()
9797
{
9898
if (requiresResultPropagation)
9999
{
100-
command.PropagateOutputParameters(reader);
100+
command.PropagateOutputParameters(reader.DbCommand.Parameters);
101101
}
102102

103103
// TODO: Rows affected via output parameter
@@ -164,26 +164,32 @@ protected override async Task ConsumeAsync(
164164
// TODO: Maybe record if there's any sprocs in the batch, and if not, skip this
165165
while (true)
166166
{
167-
if (command.StoredProcedure is not null)
167+
if (resultSetMapping.HasFlag(ResultSetMapping.HasOutputParameters))
168168
{
169-
command.PropagateOutputParameters(reader);
170-
// TODO: Rows affected via output parameter
169+
HandleOutputParameters();
171170
}
172171

173172
if (commandIndex == lastHandledCommandIndex)
174173
{
175174
break;
176175
}
177176

178-
command = ModificationCommands[++commandIndex];
177+
resultSetMapping = CommandResultSet[++commandIndex];
178+
command = ModificationCommands[commandIndex];
179+
requiresResultPropagation = command.RequiresResultPropagation;
179180
}
180181
}
181182
else if (resultSetMapping.HasFlag(ResultSetMapping.HasOutputParameters))
182183
{
183184
// Handle output parameters for commands which have no result rows. Commands with result rows are handled above.
185+
HandleOutputParameters();
186+
}
187+
188+
void HandleOutputParameters()
189+
{
184190
if (requiresResultPropagation)
185191
{
186-
command.PropagateOutputParameters(reader);
192+
command.PropagateOutputParameters(reader.DbCommand.Parameters);
187193
}
188194

189195
// TODO: Rows affected via output parameter

src/EFCore.Relational/Update/IReadOnlyModificationCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ public interface IReadOnlyModificationCommand
6969
public void PropagateResults(RelationalDataReader relationalReader);
7070

7171
/// <summary>
72-
/// Reads output parameters returned from the database in the given <paramref name="relationalReader" /> and propagates them back to
73-
/// into the appropriate <see cref="IColumnModification" /> from which the values can be propagated on to tracked entities.
72+
/// Reads output parameters returned from the database in the given <paramref name="parameterCollection" /> and propagates them back
73+
/// to into the appropriate <see cref="IColumnModification" /> from which the values can be propagated on to tracked entities.
7474
/// </summary>
75-
/// <param name="relationalReader">The relational reader containing the values read from the database.</param>
76-
public void PropagateOutputParameters(RelationalDataReader relationalReader);
75+
/// <param name="parameterCollection">The parameter collection from which to propagate output values.</param>
76+
public void PropagateOutputParameters(DbParameterCollection parameterCollection);
7777
}

src/EFCore.Relational/Update/ModificationCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ public virtual void PropagateResults(RelationalDataReader relationalReader)
500500
}
501501

502502
/// <inheritdoc />
503-
public virtual void PropagateOutputParameters(RelationalDataReader relationalReader)
503+
public virtual void PropagateOutputParameters(DbParameterCollection parameterCollection)
504504
{
505505
// Note that this call sets the value into a sidecar and will only commit to the actual entity
506506
// if SaveChanges is successful.
@@ -528,7 +528,7 @@ public virtual void PropagateOutputParameters(RelationalDataReader relationalRea
528528
// Another option is to put the invariant name in the DbParameterCollection (without the prefix); the prefix isn't needed
529529
// there AFAIK (but should check this is OK across databases.
530530
var prefixedName = "@" + columnModification.ParameterName;
531-
var dbParameter = relationalReader.DbCommand.Parameters[prefixedName];
531+
var dbParameter = parameterCollection[prefixedName];
532532
columnModification.Value = dbParameter.Value;
533533
}
534534
}

src/EFCore.Sqlite.Core/Infrastructure/Internal/SqliteModelValidator.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,10 @@ protected virtual void ValidateNoStoredProcedures(
8585
{
8686
foreach (var entityType in model.GetEntityTypes())
8787
{
88-
if (entityType.GetInsertStoredProcedureMappings().Any()
89-
|| entityType.GetUpdateStoredProcedureMappings().Any()
90-
|| entityType.GetDeleteStoredProcedureMappings().Any())
88+
if (entityType.GetInsertStoredProcedure() is not null
89+
|| entityType.GetUpdateStoredProcedure() is not null
90+
|| entityType.GetDeleteStoredProcedure() is not null)
9191
{
92-
// TODO: Make this throw and not warn (like other validations) since updates won't work
9392
throw new InvalidOperationException(SqliteStrings.StoredProceduresNotSupported(entityType.DisplayName()));
9493
}
9594
}

0 commit comments

Comments
 (0)