我正在编写一个库,它将围绕DbContextEntity Framework Core 5+ 中的类提供新的 API。我已经有了这些新 API 的一个版本,但它需要在最终DbContext实现中进行手动干预,例如:
// Code in the library.
public static class AwesomeExtensions
{
public static ModelBuilder AddAwesomeExtensionsSupportingEntities(this ModelBuilder modelBuilder)
{
// Set up custom entities I need to make this work.
return modelBuilder;
}
}
// Code somewhere else.
public class MyBusinessDbContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// I would like to avoid doing this here.
modelBuilder.AddAwesomeExtensionsSupportingEntities();
// Business as usual (database entities).
}
}
Run Code Online (Sandbox Code Playgroud)
经过长时间的搜索,我没有在 EF …