I have a program that has a number of objects (say 200).
In addition, I have an entity framework which declares a dbset for each of these.
The objects are similar (but not all identical). I feel like a factory pattern would be worthwhile here to build the objects as well as the Dbcontext dynamically.
Is it possible to dynamically build a DbContext, aligned with an object factory?
Bonus: Can the objects be defined in a tablular or text data rather than code? (easier to share a csv file with business than a few hundred lines of c#)
namespace nameObjectA
{
public class Object A
{
public Prop1
public Prop2
...
}
}
...
namespace nameObjectZ
{
public class Object Z
{
public Prop1
public Prop2
...
}
}
namespace DatabaseOps
{
public class OpsContext: DbContext
{
public DbSet<ObjectA> ObjectsA {get;set}
...
public DbSet<ObjectZ> ObjectsZ {get;set}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ObjectA>();
modelBuilder.Entity<ObjectA>().Property(x => x.Prop1);
modelBuilder.Entity<ObjectA>().Property(x => x.Prop2);
...
modelBuilder.Entity<ObjectZ>();
modelBuilder.Entity<ObjectZ>().Property(x => x.Prop1);
modelBuilder.Entity<ObjectZ>().Property(x => x.Prop2);
}
}