Skip to content

Commit

Permalink
Preiew 8: Remove non-named shared type ModelBuilder overloads (dotnet…
Browse files Browse the repository at this point in the history
…#21739)

* Remove non-named shared type ModelBuilder overloads

Based on API reviews we decided that we don't want to ship these overloads in 5.0. Ideally they belong in model pre-configuration, which we hope to implement in 6.0, so removing them from here now. Also removed the builders.
  • Loading branch information
ajcvickers committed Jul 22, 2020
1 parent f760d65 commit b76b839
Show file tree
Hide file tree
Showing 15 changed files with 1 addition and 234 deletions.
12 changes: 0 additions & 12 deletions src/EFCore/Extensions/ConventionModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,6 @@ public static string AddIgnored([NotNull] this IConventionModel model, [NotNull]
Check.NotNull(clrType, nameof(clrType)),
fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention);

/// <summary>
/// Marks the given entity type as shared, indicating that when discovered matching entity types
/// should be configured as shared type entity type.
/// </summary>
/// <param name="model"> The model to add the shared type to. </param>
/// <param name="clrType"> The type of the entity type that should be shared. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static Type AddShared([NotNull] this IConventionModel model, [NotNull] Type clrType, bool fromDataAnnotation = false)
=> Check.NotNull((Model)model, nameof(model)).AddShared(
Check.NotNull(clrType, nameof(clrType)),
fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention);

/// <summary>
/// Forces post-processing on the model such that it is ready for use by the runtime. This post
/// processing happens automatically when using <see cref="DbContext.OnModelCreating" />; this method allows it to be run
Expand Down
10 changes: 0 additions & 10 deletions src/EFCore/Extensions/MutableModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,6 @@ public static string RemoveOwned([NotNull] this IMutableModel model, [NotNull] T
=> Check.NotNull((Model)model, nameof(model)).RemoveOwned(
Check.NotNull(clrType, nameof(clrType)));

/// <summary>
/// Marks the given entity type as shared, indicating that when discovered matching entity types
/// should be configured as shared type entity type.
/// </summary>
/// <param name="model"> The model to add the shared type to. </param>
/// <param name="clrType"> The type of the entity type that should be shared. </param>
public static Type AddShared([NotNull] this IMutableModel model, [NotNull] Type clrType)
=> Check.NotNull((Model)model, nameof(model)).AddShared(
Check.NotNull(clrType, nameof(clrType)), ConfigurationSource.Explicit);

/// <summary>
/// Forces post-processing on the model such that it is ready for use by the runtime. This post
/// processing happens automatically when using <see cref="DbContext.OnModelCreating" />; this method allows it to be run
Expand Down
54 changes: 0 additions & 54 deletions src/EFCore/Metadata/Builders/SharedEntityTypeBuilder.cs

This file was deleted.

29 changes: 0 additions & 29 deletions src/EFCore/Metadata/Builders/SharedEntityTypeBuilder`.cs

This file was deleted.

28 changes: 0 additions & 28 deletions src/EFCore/Metadata/Internal/InternalModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,34 +348,6 @@ public virtual IConventionOwnedEntityTypeBuilder Owned(
private bool ShouldBeOwnedType(in TypeIdentity type)
=> type.Type != null && Metadata.IsOwned(type.Type);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual IConventionSharedEntityTypeBuilder SharedEntity(
[NotNull] Type type, ConfigurationSource configurationSource)
{
if (IsIgnored(type, configurationSource))
{
return null;
}

Metadata.RemoveIgnored(type);

foreach (var entityType in Metadata.GetEntityTypes()
.Where(et => !et.HasSharedClrType && et.ClrType == type && configurationSource.Overrides(et.GetConfigurationSource()))
.ToList())
{
HasNoEntityType(entityType, configurationSource);
}

Metadata.AddShared(type);

return new InternalSharedEntityTypeBuilder();
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand Down
17 changes: 0 additions & 17 deletions src/EFCore/Metadata/Internal/InternalSharedEntityTypeBuilder.cs

This file was deleted.

37 changes: 0 additions & 37 deletions src/EFCore/ModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,43 +477,6 @@ public virtual OwnedEntityTypeBuilder Owned([NotNull] Type type)
return new OwnedEntityTypeBuilder();
}

/// <summary>
/// <para>
/// Marks an entity type as shared type. All references to this type will be configured as separate entity types.
/// </para>
/// <para>
/// Shared type entity type is an entity type which can share CLR type with other types in the model but has
/// a unique name and always identified by the name.
/// </para>
/// </summary>
/// <typeparam name="T"> The entity type to be configured. </typeparam>
public virtual SharedEntityTypeBuilder<T> SharedEntity<T>()
where T : class
{
Builder.SharedEntity(typeof(T), ConfigurationSource.Explicit);

return new SharedEntityTypeBuilder<T>();
}

/// <summary>
/// <para>
/// Marks an entity type as shared type. All references to this type will be configured as separate entity types.
/// </para>
/// <para>
/// Shared type entity type is an entity type which can share CLR type with other types in the model but has
/// a unique name and always identified by the name.
/// </para>
/// </summary>
/// <param name="type"> The entity type to be configured. </param>
public virtual SharedEntityTypeBuilder SharedEntity([NotNull] Type type)
{
Check.NotNull(type, nameof(type));

Builder.SharedEntity(type, ConfigurationSource.Explicit);

return new SharedEntityTypeBuilder();
}

/// <summary>
/// Configures the default <see cref="ChangeTrackingStrategy" /> to be used for this model.
/// This strategy indicates how the context detects changes to properties for an instance of an entity type.
Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.Tests/ModelBuilding/ManyToManyTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public virtual void UsingEntity_with_shared_type_passed_when_marked_as_shared_ty
{
var modelBuilder = CreateModelBuilder();

modelBuilder.SharedEntity<ManyToManyJoinWithFields>();
modelBuilder.SharedEntity<ManyToManyJoinWithFields>("Shared");

var associationEntityType = modelBuilder.Entity<ManyToManyPrincipalWithField>()
.HasMany(e => e.Dependents)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ public override TestModelBuilder SharedEntity<TEntity>(string name, Action<TestE

public override TestOwnedEntityTypeBuilder<TEntity> Owned<TEntity>()
=> new GenericTestOwnedEntityTypeBuilder<TEntity>(ModelBuilder.Owned<TEntity>());
public override TestSharedEntityTypeBuilder<TEntity> SharedEntity<TEntity>()
=> new GenericTestSharedEntityTypeBuilder<TEntity>(ModelBuilder.SharedEntity<TEntity>());

public override TestModelBuilder Ignore<TEntity>()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public override TestModelBuilder SharedEntity<TEntity>(string name, Action<TestE

public override TestOwnedEntityTypeBuilder<TEntity> Owned<TEntity>()
=> new GenericTestOwnedEntityTypeBuilder<TEntity>(ModelBuilder.Owned<TEntity>());
public override TestSharedEntityTypeBuilder<TEntity> SharedEntity<TEntity>()
=> new GenericTestSharedEntityTypeBuilder<TEntity>(ModelBuilder.SharedEntity<TEntity>());

public override TestModelBuilder Ignore<TEntity>()
{
Expand Down
16 changes: 0 additions & 16 deletions test/EFCore.Tests/ModelBuilding/ModelBuilderGenericTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ public override TestEntityTypeBuilder<TEntity> Entity<TEntity>()

public override TestEntityTypeBuilder<TEntity> SharedEntity<TEntity>(string name)
=> new GenericTestEntityTypeBuilder<TEntity>(ModelBuilder.SharedEntity<TEntity>(name));
public override TestSharedEntityTypeBuilder<TEntity> SharedEntity<TEntity>()
=> new GenericTestSharedEntityTypeBuilder<TEntity>(ModelBuilder.SharedEntity<TEntity>());

public override TestModelBuilder Entity<TEntity>(Action<TestEntityTypeBuilder<TEntity>> buildAction)
{
Expand Down Expand Up @@ -363,20 +361,6 @@ public GenericTestOwnedEntityTypeBuilder(OwnedEntityTypeBuilder<TEntity> ownedEn
public OwnedEntityTypeBuilder<TEntity> Instance => OwnedEntityTypeBuilder;
}

protected class GenericTestSharedEntityTypeBuilder<TEntity> : TestSharedEntityTypeBuilder<TEntity>,
IInfrastructure<SharedEntityTypeBuilder<TEntity>>
where TEntity : class
{
public GenericTestSharedEntityTypeBuilder(SharedEntityTypeBuilder<TEntity> sharedEntityTypeBuilder)
{
SharedEntityTypeBuilder = sharedEntityTypeBuilder;
}

protected SharedEntityTypeBuilder<TEntity> SharedEntityTypeBuilder { get; }

public SharedEntityTypeBuilder<TEntity> Instance => SharedEntityTypeBuilder;
}

protected class GenericTestPropertyBuilder<TProperty> : TestPropertyBuilder<TProperty>, IInfrastructure<PropertyBuilder<TProperty>>
{
public GenericTestPropertyBuilder(PropertyBuilder<TProperty> propertyBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ public override TestModelBuilder SharedEntity<TEntity>(string name, Action<TestE
public override TestOwnedEntityTypeBuilder<TEntity> Owned<TEntity>()
=> new NonGenericTestOwnedEntityTypeBuilder<TEntity>(ModelBuilder.Owned(typeof(TEntity)));

public override TestSharedEntityTypeBuilder<TEntity> SharedEntity<TEntity>()
=> new NonGenericTestSharedEntityTypeBuilder<TEntity>(ModelBuilder.SharedEntity(typeof(TEntity)));

public override TestModelBuilder Ignore<TEntity>()
{
ModelBuilder.Ignore(typeof(TEntity));
Expand Down
17 changes: 0 additions & 17 deletions test/EFCore.Tests/ModelBuilding/ModelBuilderNonGenericTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ public override TestModelBuilder SharedEntity<TEntity>(string name, Action<TestE
public override TestOwnedEntityTypeBuilder<TEntity> Owned<TEntity>()
=> new NonGenericTestOwnedEntityTypeBuilder<TEntity>(ModelBuilder.Owned(typeof(TEntity)));

public override TestSharedEntityTypeBuilder<TEntity> SharedEntity<TEntity>()
=> new NonGenericTestSharedEntityTypeBuilder<TEntity>(ModelBuilder.SharedEntity(typeof(TEntity)));

public override TestModelBuilder Ignore<TEntity>()
{
ModelBuilder.Ignore(typeof(TEntity));
Expand Down Expand Up @@ -347,20 +344,6 @@ public NonGenericTestOwnedEntityTypeBuilder(OwnedEntityTypeBuilder ownedEntityTy
public OwnedEntityTypeBuilder Instance => OwnedEntityTypeBuilder;
}

protected class NonGenericTestSharedEntityTypeBuilder<TEntity> : TestSharedEntityTypeBuilder<TEntity>,
IInfrastructure<SharedEntityTypeBuilder>
where TEntity : class
{
public NonGenericTestSharedEntityTypeBuilder(SharedEntityTypeBuilder sharedEntityTypeBuilder)
{
SharedEntityTypeBuilder = sharedEntityTypeBuilder;
}

protected SharedEntityTypeBuilder SharedEntityTypeBuilder { get; }

public SharedEntityTypeBuilder Instance => SharedEntityTypeBuilder;
}

protected class NonGenericTestPropertyBuilder<TProperty> : TestPropertyBuilder<TProperty>, IInfrastructure<PropertyBuilder>
{
public NonGenericTestPropertyBuilder(PropertyBuilder propertyBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ public override TestModelBuilder SharedEntity<TEntity>(string name, Action<TestE
public override TestOwnedEntityTypeBuilder<TEntity> Owned<TEntity>()
=> new NonGenericTestOwnedEntityTypeBuilder<TEntity>(ModelBuilder.Owned(typeof(TEntity)));

public override TestSharedEntityTypeBuilder<TEntity> SharedEntity<TEntity>()
=> new NonGenericTestSharedEntityTypeBuilder<TEntity>(ModelBuilder.SharedEntity(typeof(TEntity)));

public override TestModelBuilder Ignore<TEntity>()
{
ModelBuilder.Ignore(typeof(TEntity));
Expand Down
3 changes: 0 additions & 3 deletions test/EFCore.Tests/ModelBuilding/ModelBuilderTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ public abstract TestEntityTypeBuilder<TEntity> SharedEntity<TEntity>(string name
public abstract TestOwnedEntityTypeBuilder<TEntity> Owned<TEntity>()
where TEntity : class;

public abstract TestSharedEntityTypeBuilder<TEntity> SharedEntity<TEntity>()
where TEntity : class;

public abstract TestModelBuilder Entity<TEntity>(Action<TestEntityTypeBuilder<TEntity>> buildAction)
where TEntity : class;

Expand Down

0 comments on commit b76b839

Please sign in to comment.