-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Expose Current ConventionSet #5737
Comments
@rjperes The As an example if you want to replace the public class CustomSqlServerConventionSetBuilder : SqlServerConventionSetBuilder
{
public CustomSqlServerConventionSetBuilder(
IRelationalTypeMapper typeMapper, ICurrentDbContext currentContext, IDbSetFinder setFinder)
: base(typeMapper, currentContext, setFinder)
{
}
public override ConventionSet AddConventions(ConventionSet conventionSet)
{
base.AddConventions(conventionSet);
conventionSet.ModelInitializedConventions.Add(new SqlServerValueGenerationStrategyConvention());
var relationshipDiscoveryConvention =
conventionSet.EntityTypeAddedConventions.OfType<RelationshipDiscoveryConvention>().FirstOrDefault();
var index = conventionSet.EntityTypeAddedConventions.IndexOf(relationshipDiscoveryConvention);
conventionSet.EntityTypeAddedConventions.RemoveAt(index);
conventionSet.EntityTypeAddedConventions.Insert(index, new BetterRelationshipDiscoveryConvention());
return conventionSet;
}
} Then add it to DI: services
.AddEntityFrameworkSqlServer()
.AddScoped<SqlServerConventionSetBuilder, CustomSqlServerConventionSetBuilder>() This experience will be improved by #214 |
Well, you didn't explain anything that I didn't knew. The point of this PR was precisely to change that, by giving developers a chance to add conventions at runtime without the need to subclass an infrastructure class. |
Changing the conventions in |
So what? That is exactly what happened with custom conventions in EF pre-Core! |
The way conventions are applied in EF Core is fundamentally different from EF6. In EF6 However in EF Core the configuration specified in |
As of now, the current ConventionSet is not publicly exposed. It is only possible, AFAIK, to get a pointer to it by using reflection to access the _conventionSet field of the ConventionDispatcher.
In order to make conventions simpler to use, can't you expose the current ConventionSet as a property somewhere?
The text was updated successfully, but these errors were encountered: