Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TPH sibling metadata bug #29025

Merged
merged 1 commit into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 20 additions & 26 deletions src/EFCore.Relational/Metadata/Internal/RelationalModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,21 +1133,18 @@ private static StoredProcedureMapping CreateStoredProcedureMapping(
entityType.GetMappingStrategy() == RelationalAnnotationNames.TphMappingStrategy,
"Expected TPH for " + entityType.DisplayName());

if (entityType.BaseType == null)
foreach (var derivedProperty in entityType.GetRootType().GetDerivedProperties())
{
foreach (var derivedProperty in entityType.GetDerivedProperties())
if (derivedProperty.Name == parameter.PropertyName)
{
if (derivedProperty.Name == parameter.PropertyName)
{
GetOrCreateStoreStoredProcedureParameter(
parameter,
derivedProperty,
position,
storeStoredProcedure,
identifier,
relationalTypeMappingSource);
break;
}
GetOrCreateStoreStoredProcedureParameter(
parameter,
derivedProperty,
position,
storeStoredProcedure,
identifier,
relationalTypeMappingSource);
break;
}
}

Expand Down Expand Up @@ -1201,21 +1198,18 @@ private static StoredProcedureMapping CreateStoredProcedureMapping(
entityType.GetMappingStrategy() == RelationalAnnotationNames.TphMappingStrategy,
"Expected TPH for " + entityType.DisplayName());

if (entityType.BaseType == null)
foreach (var derivedProperty in entityType.GetRootType().GetDerivedProperties())
{
foreach (var derivedProperty in entityType.GetDerivedProperties())
if (derivedProperty.Name == resultColumn.PropertyName)
{
if (derivedProperty.Name == resultColumn.PropertyName)
{
GetOrCreateStoreStoredProcedureResultColumn(
resultColumn,
derivedProperty,
position,
storeStoredProcedure,
identifier,
relationalTypeMappingSource);
break;
}
GetOrCreateStoreStoredProcedureResultColumn(
resultColumn,
derivedProperty,
position,
storeStoredProcedure,
identifier,
relationalTypeMappingSource);
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
.HasParameter(w => w.Id, pb => pb.IsOutput())
.HasParameter("Discriminator")
.HasParameter(w => w.Name)
.HasParameter(nameof(TphChild1.Child1Property))
.HasParameter(nameof(TphChild2.Child2InputProperty))
.HasParameter(nameof(TphChild2.Child2OutputParameterProperty), o => o.IsOutput())
.HasParameter(nameof(TphChild1.Child1Property))
.HasResultColumn(nameof(TphChild2.Child2ResultColumnProperty)));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,12 @@ public override async Task Tph(bool async)
@"@p0=NULL (Nullable = false) (Direction = Output) (DbType = Int32)
@p1='TphChild1' (Nullable = false) (Size = 4000)
@p2='Child' (Size = 4000)
@p3='8' (Nullable = true)
@p4=NULL (DbType = Int32)
@p5=NULL (Direction = Output) (DbType = Int32)
@p3=NULL (DbType = Int32)
@p4=NULL (Direction = Output) (DbType = Int32)
@p5='8' (Nullable = true)

SET NOCOUNT ON;
EXEC [Tph_Insert] @p0 OUTPUT, @p1, @p2, @p3, @p4, @p5 OUTPUT;");
EXEC [Tph_Insert] @p0 OUTPUT, @p1, @p2, @p3, @p4 OUTPUT, @p5;");
}

public override async Task Tpt(bool async)
Expand Down Expand Up @@ -576,7 +576,7 @@ IF @Name IS NULL

GO

CREATE PROCEDURE Tph_Insert(@Id int OUT, @Discriminator varchar(max), @Name varchar(max), @Child1Property int, @Child2InputProperty int, @Child2OutputParameterProperty int OUT)
CREATE PROCEDURE Tph_Insert(@Id int OUT, @Discriminator varchar(max), @Name varchar(max), @Child2InputProperty int, @Child2OutputParameterProperty int OUT, @Child1Property int)
AS BEGIN
DECLARE @Table table ([Child2OutputParameterProperty] int);
INSERT INTO [Tph] ([Discriminator], [Name], [Child1Property], [Child2InputProperty]) OUTPUT [Inserted].[Child2OutputParameterProperty] INTO @Table VALUES (@Discriminator, @Name, @Child1Property, @Child2InputProperty);
Expand Down