allowing a user to define a table at runtime using entity framework

.net c# entity-framework entity-framework-6

Popular Answer

Reflection can be used to dynamically construct an EF model:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    var entityMethod = typeof(DbModelBuilder).GetMethod("Entity");

    foreach (Type type in ...)
    {
        entityMethod.MakeGenericMethod(type)
            .Invoke(modelBuilder, new object[] { });
    }
    base.OnModelCreating(modelBuilder);
}
1
4/25/2015 10:56:20 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow