The API for conventions is currently not stable. See https://github.com/aspnet/EntityFramework/issues/2589 .
This can be done, but it requires the use of dependency nesting to redefine the inner workings of how OnModelCreating is called in your context. DbContext uses dependency injection to find the ModelSource instance that the model builder (and conventions) provides.
To override the model source, add your own implementation to the dependency injection:
var serviceCollection = new ServiceCollection(); serviceCollection .AddEntityFramework() .AddSqlServer(); serviceCollection.AddSingleton<SqlServerModelSource, MyModelSource>(); var serviceProvider = serviceCollection.BuildServiceProvider(); using(var context = new MyContext(serviceProvider)) {
Your MyModelSource implementation should override ModelSource.CreateConventionSet() . See source
source share