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

Add a generic overload of ConventionSetBuilder.Remove #29499

Merged
merged 1 commit into from
Nov 8, 2022
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
8 changes: 8 additions & 0 deletions src/EFCore/Metadata/Builders/ConventionSetBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ public virtual void Add(Func<IServiceProvider, IConvention> conventionFactory)
public virtual void Remove(Type conventionType)
=> _conventionSet.Remove(conventionType);

/// <summary>
/// Remove the convention of the given type.
/// </summary>
/// <typeparam name="TImplementaion">The type of convention to remove</typeparam>
public virtual void Remove<TImplementaion>()
where TImplementaion : IConvention
=> Remove(typeof(TImplementaion));

#region Hidden System.Object members

/// <summary>
Expand Down
15 changes: 15 additions & 0 deletions test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,21 @@ public virtual void Conventions_can_be_removed()

var model = modelBuilder.FinalizeModel();

Assert.Null(model["foo"]);
}

[ConditionalFact]
public virtual void Conventions_can_be_removed_by_generic_method()
{
var modelBuilder = CreateModelBuilder(
c =>
{
c.Conventions.Add(s => new TestConvention());
c.Conventions.Remove<TestConvention>();
});

var model = modelBuilder.FinalizeModel();

Assert.Null(model["foo"]);
}

Expand Down