Ok, so I'm trying to access the .Map function in a FluentApi EF6 setup. Here's what I've got so far:
// First, get our DbModel.Entity<> method, and make it a generic of the dbSetType Type variable
MethodInfo dbModelMethodInfo = typeof(DbModelBuilder).GetMethod("Entity").MakeGenericMethod(dbSetType);
// Now, since we'd have normally chained this, with reflection we want to take the return type
// from dbModelMethodInfo and grab the ToTable Method, specifically the (string, string) constructor
MethodInfo entityTypeConfigInfo = dbModelMethodInfo.ReturnType.GetMethod("ToTable", new[] { typeof(String), typeof(String) });
MethodInfo[] methodInfoArray = dbModelMethodInfo.ReturnType.GetMethods(BindingFlags.Public | BindingFlags.Instance);
// We also need to grab the Map if it's changed
MethodInfo entityTypeMappingInfo = dbModelMethodInfo.ReturnType.GetMethod("Map", new[] { typeof(Action) });
Long story short, I'm remapping an Oracle EF Schema @ runtime. The MethodInfo[] is just there as my exploration of 'Hey, what's available?' and I'm remapping the ToTable without issue. I need to remap the Maps as well, which is something like:
modelBuilder.Entity<Table1>()
.HasMany(e => e.Table2)
.WithMany(e => e.Table1)
.Map(m => m.ToTable("TABLE_1", "SCHEMA_1").MapLeftKey("KEY_1").MapRightKey("KEY_2"));
I need to (at runtime) get the SCHEMA_1 from the m.ToTable and remap to SCHEMA_2 (again, dynamically).
So the question I'm trying to ask is: Does anyone have an example of trying to grab an Action() at runtime?
I'm specifically dealing with: Map(Action(Of EntityMappingConfiguration(Of TEntityType)))
Thanks!
Aucun commentaire:
Enregistrer un commentaire