private void ValidateClrInheritance( IModel model, IEntityType entityType, HashSet <IEntityType> validEntityTypes) { if (validEntityTypes.Contains(entityType)) { return; } if (entityType.HasSharedClrType && entityType.BaseType != null) { throw new InvalidOperationException(CoreStrings.SharedTypeDerivedType(entityType.DisplayName())); } if (entityType.FindDeclaredOwnership() == null && entityType.BaseType != null) { var baseClrType = entityType.ClrType.BaseType; while (baseClrType != null) { var baseEntityType = model.FindEntityType(baseClrType); if (baseEntityType != null) { if (!baseEntityType.IsAssignableFrom(entityType)) { throw new InvalidOperationException( CoreStrings.InconsistentInheritance( entityType.DisplayName(), entityType.BaseType.DisplayName(), baseEntityType.DisplayName())); } break; } baseClrType = baseClrType.BaseType; } } if (!entityType.ClrType.IsInstantiable() && !entityType.GetDerivedTypes().Any()) { throw new InvalidOperationException( CoreStrings.AbstractLeafEntityType(entityType.DisplayName())); } validEntityTypes.Add(entityType); }
private void ValidateClrInheritance( [NotNull] IModel model, [NotNull] IEntityType entityType, [NotNull] HashSet <IEntityType> validEntityTypes, DiagnosticsLoggers loggers) { Check.NotNull(model, nameof(model)); Check.NotNull(entityType, nameof(entityType)); Check.NotNull(validEntityTypes, nameof(validEntityTypes)); if (validEntityTypes.Contains(entityType)) { return; } if (!entityType.HasDefiningNavigation() && entityType.FindDeclaredOwnership() == null && entityType.BaseType != null) { var baseClrType = entityType.ClrType?.GetTypeInfo().BaseType; while (baseClrType != null) { var baseEntityType = model.FindEntityType(baseClrType); if (baseEntityType != null) { if (!baseEntityType.IsAssignableFrom(entityType)) { throw new InvalidOperationException( CoreStrings.InconsistentInheritance(entityType.DisplayName(), baseEntityType.DisplayName())); } break; } baseClrType = baseClrType.GetTypeInfo().BaseType; } } if (entityType.ClrType?.IsInstantiable() == false && !entityType.GetDerivedTypes().Any()) { throw new InvalidOperationException( CoreStrings.AbstractLeafEntityType(entityType.DisplayName())); } validEntityTypes.Add(entityType); }