I want to add Include
s dynamically from input params[]
. How can I do this?
This is my code
IQueryable<Work> query = this.ObjectContext.Works
.Include("EmployeeSender.Person")
.Include("EmployeeReceiver.Person")
.Include("WorkCode")
.Include("WorkFlowStep.WorkFlowFormState")
.Include("WorkFlow")
.Include("WorkRoot.EmployeeSender.Person")
.Include("WorkParent");
In a loop, for example:
IQueryable<Work> query = null;
query = this.ObjectContext.Works;
foreach (var param in params)
{
query = query.Include(param);
}
var result = query.ToList();
As Christian Dietz mentioned, you can then put this in an extension method so that it becomes reusable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With