My .Net Core application has a DbContext with several DBSet<> properties. However, I want to also add additional entities to the DbContext. They have System.ComponentModel.DataAnnotations, the same as the ones defined with DBSet. That way I can create and
use an instance of MyDbContext.Set<MyEntity>, or MyDbContext.Set(MyEntity), or even with the reflection API, which could be wrapped.
The examples I have tried so far involved overriding OnModelCreating() and attempting to create a new generic Set<> method for the DbContext using reflection. One would think the metadata that would drive the generation of table schemas/SQL DDL and SQL commands
would be derived from the entity, similarly to how it would be instantiated using the DBSet<> syntax. A promising class was EntityTypeBuilder<> which seems to extract the entity's metadata, but the method ModelBuilder.ApplyConfiguration() takes a IEntityTypeConfiguration
and has no implementation.
I have searched both this forum's posts as well as read entire issues (#2805, #8434, #2282,
#3438, and many others) on the Entity Framework Core github site. If there is some magic missing class, please let me know. Or a HowTo link. If this is not possible, know that would also
be great. Thank you.
↧
Adding Set to DBContext
↧