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

Metadata: Throw error for shared type in inheritance #21715

Merged
1 commit merged into from
Jul 21, 2020
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
6 changes: 6 additions & 0 deletions src/EFCore/Infrastructure/ModelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,12 @@ private void ValidateClrInheritance(
return;
}

if (entityType.HasSharedClrType
&& entityType.BaseType != null)
{
throw new InvalidOperationException(CoreStrings.SharedTypeDerivedType(entityType.DisplayName()));
}

if (!entityType.HasDefiningNavigation()
&& entityType.FindDeclaredOwnership() == null
&& entityType.BaseType != null)
Expand Down
8 changes: 8 additions & 0 deletions src/EFCore/Properties/CoreStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/EFCore/Properties/CoreStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1441,4 +1441,7 @@
<data name="TypeNotMarkedAsShared" xml:space="preserve">
<value>Type '{type}' is not been configured as shared type in the model. Before calling 'UsingEntity', please mark the type as shared or add the entity type in the model as shared entity.</value>
</data>
<data name="SharedTypeDerivedType" xml:space="preserve">
<value>The shared type entity type '{entityType}' cannot have a base type.</value>
</data>
</root>
10 changes: 10 additions & 0 deletions test/EFCore.Tests/Infrastructure/ModelValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,16 @@ public virtual void Required_navigation_with_query_filter_on_both_sides_doesnt_i
VerifyLogDoesNotContain(message, modelBuilder.Model);
}

[ConditionalFact]
public virtual void Shared_type_inheritance_throws()
{
var modelBuilder = CreateConventionalModelBuilder();
modelBuilder.SharedEntity<A>("Shared1");
modelBuilder.SharedEntity<C>("Shared2").HasBaseType("Shared1");

VerifyError(CoreStrings.SharedTypeDerivedType("Shared2"), modelBuilder.Model);
}

// INotify interfaces not really implemented; just marking the classes to test metadata construction
private class FullNotificationEntity : INotifyPropertyChanging, INotifyPropertyChanged
{
Expand Down