Skip to content

Commit

Permalink
Sproc sample fixes (#4020)
Browse files Browse the repository at this point in the history
  • Loading branch information
roji authored Sep 12, 2022
1 parent 10cd2e6 commit bd740ea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
49 changes: 24 additions & 25 deletions samples/core/Miscellaneous/NewInEFCore7/DocumentsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Person_Update",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter(person => person.Id);
storedProcedureBuilder.HasOriginalValueParameter(person => person.Id);
storedProcedureBuilder.HasOriginalValueParameter(
person => person.Name, parameterBuilder => parameterBuilder.HasName("Name_Original"));
storedProcedureBuilder.HasParameter(person => person.Name);
Expand All @@ -126,7 +126,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Person_Delete",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter(person => person.Id);
storedProcedureBuilder.HasOriginalValueParameter(person => person.Id);
storedProcedureBuilder.HasOriginalValueParameter(person => person.Name);
storedProcedureBuilder.HasRowsAffectedResultColumn();
});
Expand All @@ -151,15 +151,15 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Contacts_Update",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter("PersonId");
storedProcedureBuilder.HasOriginalValueParameter("PersonId");
storedProcedureBuilder.HasParameter(contactDetails => contactDetails.Phone);
storedProcedureBuilder.HasRowsAffectedResultColumn();
});
ownedNavigationBuilder.DeleteUsingStoredProcedure(
"Contacts_Delete", storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter("PersonId");
storedProcedureBuilder.HasOriginalValueParameter("PersonId");
storedProcedureBuilder.HasRowsAffectedResultColumn();
});
}
Expand All @@ -186,7 +186,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Addresses_Update",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter("ContactDetailsPersonId");
storedProcedureBuilder.HasOriginalValueParameter("ContactDetailsPersonId");
storedProcedureBuilder.HasParameter(address => address.Street);
storedProcedureBuilder.HasParameter(address => address.City);
storedProcedureBuilder.HasParameter(address => address.Postcode);
Expand All @@ -197,7 +197,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
ownedOwnedNavigationBuilder.DeleteUsingStoredProcedure(
"Addresses_Delete", storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter("ContactDetailsPersonId");
storedProcedureBuilder.HasOriginalValueParameter("ContactDetailsPersonId");
storedProcedureBuilder.HasRowsAffectedResultColumn();
});
}
Expand Down Expand Up @@ -293,8 +293,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Document_Update",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter(document => document.Id);
storedProcedureBuilder.HasParameter("Discriminator");
storedProcedureBuilder.HasOriginalValueParameter(document => document.Id);
storedProcedureBuilder.HasOriginalValueParameter(
document => document.RowVersion,
parameterBuilder => parameterBuilder.HasName("RowVersion_Original"));
Expand All @@ -318,7 +317,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Document_Delete",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter(document => document.Id);
storedProcedureBuilder.HasOriginalValueParameter(document => document.Id);
storedProcedureBuilder.HasOriginalValueParameter(document => document.RowVersion);
storedProcedureBuilder.HasRowsAffectedResultColumn();
});
Expand Down Expand Up @@ -351,8 +350,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"BookPerson_Delete",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter("AuthorsId");
storedProcedureBuilder.HasParameter("PublishedWorksId");
storedProcedureBuilder.HasOriginalValueParameter("AuthorsId");
storedProcedureBuilder.HasOriginalValueParameter("PublishedWorksId");
storedProcedureBuilder.HasRowsAffectedResultColumn();
});
}
Expand Down Expand Up @@ -394,7 +393,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Document_Update",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter(document => document.Id);
storedProcedureBuilder.HasOriginalValueParameter(document => document.Id);
storedProcedureBuilder.HasOriginalValueParameter(
document => document.RowVersion,
parameterBuilder => parameterBuilder.HasName("RowVersion_Original"));
Expand All @@ -414,7 +413,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Document_Delete",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter(document => document.Id);
storedProcedureBuilder.HasOriginalValueParameter(document => document.Id);
storedProcedureBuilder.HasOriginalValueParameter(document => document.RowVersion);
storedProcedureBuilder.HasRowsAffectedResultColumn();
});
Expand Down Expand Up @@ -447,8 +446,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"BookPerson_Delete",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter("AuthorsId");
storedProcedureBuilder.HasParameter("PublishedWorksId");
storedProcedureBuilder.HasOriginalValueParameter("AuthorsId");
storedProcedureBuilder.HasOriginalValueParameter("PublishedWorksId");
storedProcedureBuilder.HasRowsAffectedResultColumn();
});
}
Expand All @@ -468,7 +467,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Book_Update",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter(book => book.Id);
storedProcedureBuilder.HasOriginalValueParameter(book => book.Id);
storedProcedureBuilder.HasParameter(book => book.Isbn);
storedProcedureBuilder.HasRowsAffectedResultColumn();
});
Expand All @@ -477,7 +476,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Book_Delete",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter(book => book.Id);
storedProcedureBuilder.HasOriginalValueParameter(book => book.Id);
storedProcedureBuilder.HasRowsAffectedResultColumn();
});
}
Expand All @@ -502,7 +501,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Magazine_Update",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter(magazine => magazine.Id);
storedProcedureBuilder.HasOriginalValueParameter(magazine => magazine.Id);
storedProcedureBuilder.HasParameter(magazine => magazine.CoverPrice);
storedProcedureBuilder.HasParameter(magazine => magazine.IssueNumber);
storedProcedureBuilder.HasParameter("EditorId");
Expand All @@ -513,7 +512,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Magazine_Delete",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter(magazine => magazine.Id);
storedProcedureBuilder.HasOriginalValueParameter(magazine => magazine.Id);
storedProcedureBuilder.HasRowsAffectedResultColumn();
});
}
Expand Down Expand Up @@ -557,8 +556,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"BookPerson_Delete",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter("AuthorsId");
storedProcedureBuilder.HasParameter("PublishedWorksId");
storedProcedureBuilder.HasOriginalValueParameter("AuthorsId");
storedProcedureBuilder.HasOriginalValueParameter("PublishedWorksId");
storedProcedureBuilder.HasRowsAffectedResultColumn();
});
}
Expand All @@ -585,7 +584,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Book_Update",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter(book => book.Id);
storedProcedureBuilder.HasOriginalValueParameter(book => book.Id);
storedProcedureBuilder.HasOriginalValueParameter(
magazine => magazine.RowVersion,
parameterBuilder => parameterBuilder.HasName("RowVersion_Original"));
Expand All @@ -606,7 +605,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Book_Delete",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter(book => book.Id);
storedProcedureBuilder.HasOriginalValueParameter(book => book.Id);
storedProcedureBuilder.HasOriginalValueParameter(book => book.RowVersion);
storedProcedureBuilder.HasRowsAffectedResultColumn();
});
Expand Down Expand Up @@ -639,7 +638,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Magazine_Update",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter(magazine => magazine.Id);
storedProcedureBuilder.HasOriginalValueParameter(magazine => magazine.Id);
storedProcedureBuilder.HasOriginalValueParameter(
magazine => magazine.RowVersion,
parameterBuilder => parameterBuilder.HasName("RowVersion_Original"));
Expand All @@ -662,7 +661,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
"Magazine_Delete",
storedProcedureBuilder =>
{
storedProcedureBuilder.HasParameter(magazine => magazine.Id);
storedProcedureBuilder.HasOriginalValueParameter(magazine => magazine.Id);
storedProcedureBuilder.HasOriginalValueParameter(magazine => magazine.RowVersion);
storedProcedureBuilder.HasRowsAffectedResultColumn();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ await context.Database.ExecuteSqlRawAsync(
@"
CREATE PROCEDURE [dbo].[Document_Update]
@Id [int],
@Discriminator [nvarchar](max),
@RowVersion_Original [rowversion],
@Title [nvarchar](max),
@NumberOfPages [int],
Expand All @@ -47,7 +46,6 @@ @RowVersion [rowversion] OUT
AS
BEGIN
UPDATE [Documents] SET
[Discriminator] = @Discriminator,
[Title] = @Title,
[NumberOfPages] = @NumberOfPages,
[PublicationDate] = @PublicationDate,
Expand Down
12 changes: 6 additions & 6 deletions samples/core/Miscellaneous/NewInEFCore7/ExecuteUpdateSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ private static async Task ResetPostPublishedOnToDefault<TContext>()
$"Posts before update: {string.Join(", ", await context.Posts.AsNoTracking().Select(e => "'..." + e.Title.Substring(e.Title.Length - 12) + "' " + e.PublishedOn.Date).ToListAsync())}");
Console.WriteLine();

context.LoggingEnabled = true;
await context.Set<Post>()
.ExecuteUpdateAsync(
setPropertyCalls => setPropertyCalls
.SetProperty(post => post.PublishedOn, post => EF.Default<DateTime>()));
context.LoggingEnabled = false;
// context.LoggingEnabled = true;
// await context.Set<Post>()
// .ExecuteUpdateAsync(
// setPropertyCalls => setPropertyCalls
// .SetProperty(post => post.PublishedOn, post => EF.Default<DateTime>()));
// context.LoggingEnabled = false;

Console.WriteLine();
Console.WriteLine(
Expand Down

0 comments on commit bd740ea

Please sign in to comment.