diff --git a/src/EFCore/Infrastructure/ModelValidator.cs b/src/EFCore/Infrastructure/ModelValidator.cs
index ea5873c5a97..6304b645d44 100644
--- a/src/EFCore/Infrastructure/ModelValidator.cs
+++ b/src/EFCore/Infrastructure/ModelValidator.cs
@@ -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)
diff --git a/src/EFCore/Properties/CoreStrings.Designer.cs b/src/EFCore/Properties/CoreStrings.Designer.cs
index 497a6e09dcd..caec74accda 100644
--- a/src/EFCore/Properties/CoreStrings.Designer.cs
+++ b/src/EFCore/Properties/CoreStrings.Designer.cs
@@ -2740,6 +2740,14 @@ public static string TypeNotMarkedAsShared([CanBeNull] object type)
GetString("TypeNotMarkedAsShared", nameof(type)),
type);
+ ///
+ /// The shared type entity type '{entityType}' cannot have a base type.
+ ///
+ public static string SharedTypeDerivedType([CanBeNull] object entityType)
+ => string.Format(
+ GetString("SharedTypeDerivedType", nameof(entityType)),
+ entityType);
+
private static string GetString(string name, params string[] formatterNames)
{
var value = _resourceManager.GetString(name);
diff --git a/src/EFCore/Properties/CoreStrings.resx b/src/EFCore/Properties/CoreStrings.resx
index 07c4b3b7d95..4c4ee5a7896 100644
--- a/src/EFCore/Properties/CoreStrings.resx
+++ b/src/EFCore/Properties/CoreStrings.resx
@@ -1441,4 +1441,7 @@
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.
+
+ The shared type entity type '{entityType}' cannot have a base type.
+
\ No newline at end of file
diff --git a/test/EFCore.Tests/Infrastructure/ModelValidatorTest.cs b/test/EFCore.Tests/Infrastructure/ModelValidatorTest.cs
index b301c5b52f9..e92e9e18bee 100644
--- a/test/EFCore.Tests/Infrastructure/ModelValidatorTest.cs
+++ b/test/EFCore.Tests/Infrastructure/ModelValidatorTest.cs
@@ -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("Shared1");
+ modelBuilder.SharedEntity("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
{