Skip to content

Commit

Permalink
Suffix original value sproc parameters by default
Browse files Browse the repository at this point in the history
Fixes #28817
  • Loading branch information
AndriySvyryd authored Aug 24, 2022
1 parent 915000c commit 510878d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,26 @@ public override bool IsReadOnly
/// </summary>
public virtual string Name
{
get => _name ?? (ForRowsAffected
? "RowsAffected"
: GetProperty().GetDefaultColumnName(
((IReadOnlyStoredProcedure)StoredProcedure).GetStoreIdentifier()!.Value)!);
get
{
if (_name != null)
{
return _name;
}

if (ForRowsAffected)
{
return "RowsAffected";
}
else
{
var baseName = GetProperty().GetDefaultColumnName(
((IReadOnlyStoredProcedure)StoredProcedure).GetStoreIdentifier()!.Value)!;
return ForOriginalValue ?? false
? Uniquifier.Truncate(baseName + "_Original", GetProperty().DeclaringEntityType.Model.GetMaxIdentifierLength())
: baseName;
}
}
set => SetName(value, ConfigurationSource.Explicit);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ public virtual void Sproc_overrides_update_when_renamed_in_TPH()
s => s.HasAnnotation("foo", "bar3")
.HasParameter(b => b.Id, p => p.HasName("DeleteId"))
.HasRowsAffectedResultColumn()
.HasParameter("RowVersion")
.HasOriginalValueParameter("RowVersion"));

modelBuilder.Entity<SpecialBookLabel>()
Expand Down Expand Up @@ -454,6 +455,7 @@ public virtual void Sproc_overrides_update_when_renamed_in_TPH()
Assert.Equal("Update", updateSproc.Name);
Assert.Equal("dbo", updateSproc.Schema);
Assert.Equal(new[] { "Id", "BookId", null, "RowVersion", "RowVersion" }, updateSproc.Parameters.Select(p => p.PropertyName));
Assert.Equal(new[] { "UpdateId", "BookId", "RowsAffected", "OriginalRowVersion", "RowVersion" }, updateSproc.Parameters.Select(p => p.Name));
Assert.Empty(updateSproc.ResultColumns);
Assert.Equal("bar2", updateSproc["foo"]);
Assert.Same(bookLabel, updateSproc.EntityType);
Expand All @@ -480,7 +482,8 @@ public virtual void Sproc_overrides_update_when_renamed_in_TPH()
var deleteSproc = bookLabel.GetDeleteStoredProcedure()!;
Assert.Equal("BookLabel_Delete", deleteSproc.Name);
Assert.Equal("mySchema", deleteSproc.Schema);
Assert.Equal(new[] { "Id", "RowVersion" }, deleteSproc.Parameters.Select(p => p.PropertyName));
Assert.Equal(new[] { "Id", "RowVersion", "RowVersion" }, deleteSproc.Parameters.Select(p => p.PropertyName));
Assert.Equal(new[] { "DeleteId", "RowVersion", "RowVersion_Original" }, deleteSproc.Parameters.Select(p => p.Name));
Assert.Equal(new[] { "RowsAffected" }, deleteSproc.ResultColumns.Select(p => p.Name));
Assert.Equal("bar3", deleteSproc["foo"]);
Assert.Same(bookLabel, deleteSproc.EntityType);
Expand Down

0 comments on commit 510878d

Please sign in to comment.