Skip to content

Commit

Permalink
Fix relational overrides validation for non-inheritance case (#23834)
Browse files Browse the repository at this point in the history
Fixes #23832
  • Loading branch information
roji committed Jan 8, 2021
1 parent 60ef9cc commit fc29d1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ protected virtual void ValidatePropertyOverrides(
switch (storeOverride.StoreObjectType)
{
case StoreObjectType.Table:
if (!entityType.GetDerivedTypes().Any(
if (!entityType.GetDerivedTypesInclusive().Any(
d =>
d.GetTableName() == name
&& d.GetSchema() == schema))
Expand All @@ -1222,7 +1222,7 @@ protected virtual void ValidatePropertyOverrides(

break;
case StoreObjectType.View:
if (!entityType.GetDerivedTypes().Any(
if (!entityType.GetDerivedTypesInclusive().Any(
d =>
d.GetViewName() == name
&& d.GetViewSchema() == schema))
Expand All @@ -1235,7 +1235,7 @@ protected virtual void ValidatePropertyOverrides(

break;
case StoreObjectType.SqlQuery:
if (!entityType.GetDerivedTypes().Any(d => d.GetDefaultSqlQueryName() == name))
if (!entityType.GetDerivedTypesInclusive().Any(d => d.GetDefaultSqlQueryName() == name))
{
throw new InvalidOperationException(
RelationalStrings.SqlQueryOverrideMismatch(
Expand All @@ -1244,7 +1244,7 @@ protected virtual void ValidatePropertyOverrides(

break;
case StoreObjectType.Function:
if (!entityType.GetDerivedTypes().Any(d => d.GetFunctionName() == name))
if (!entityType.GetDerivedTypesInclusive().Any(d => d.GetFunctionName() == name))
{
throw new InvalidOperationException(
RelationalStrings.FunctionOverrideMismatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,22 @@ public virtual void Non_TPH_as_a_result_of_DbFunction_throws()
TestMethods.MethodFMi.DeclaringType.FullName + "." + TestMethods.MethodFMi.Name + "()", "C"), modelBuilder.Model);
}

[ConditionalFact]
public virtual void Passes_for_relational_override_without_inheritance()
{
var modelBuilder = CreateConventionalModelBuilder();
modelBuilder.Entity<Person>(
e =>
{
e.ToTable("foo");
e.Property(p => p.Name).Metadata.SetColumnName("bar", StoreObjectIdentifier.Table("foo", null));
});

Validate(modelBuilder.Model);

Assert.DoesNotContain(LoggerFactory.Log, l => l.Level == LogLevel.Warning);
}

private static void GenerateMapping(IMutableProperty property)
=> property.SetTypeMapping(
new TestRelationalTypeMappingSource(
Expand Down

0 comments on commit fc29d1c

Please sign in to comment.