I have to dynamically select from an arbitrary table :
IEnumerable<object> table = typeof(MyContext).GetProperty(tblName).GetValue(context, null) as IEnumerable<object>;
But now there is 1 more problem, I can't seem to find a way to include
the related entities into the dynamic table
above :
string relations= "relatedentity1,relatedentity2,relatedentity3"
relatedEntities = relations.Split(',');
foreach (string relatedEntity in relatedEntities)
{
(table as ObjectQuery<object>).Include(relatedEntity); // error line
}
This approach is giving me this error (the table
object is not null
) :
Object reference not set to an instance of an object.
Normally, this is how it's done :
MaterialStartingBalance = (from a in context.MaterialStartingBalance
.Include("Warehouse")
.Include("Account")
.Include("Material")
.Include("SalesOrder")
select a).ToList();
How do I achieve this? Thanks alot!