Skip to content

Commit

Permalink
Fix TPH sproc relational model
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriySvyryd authored and roji committed Sep 9, 2022
1 parent a7b82d0 commit 4919080
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 32 deletions.
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

0 comments on commit 4919080

Please sign in to comment.