❔ Expression<Func> using Reflection

Hello,

I'm using LINQ to SQL as part of an old legacy Business Object Layer and trying to use the following code using reflection instead of hardcoding the types.

Currently I have:
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith<WorkRequest>(m => m.WorkRequestItems);
dc.LoadOptions = loadOptions;
Table table = dc.GetTable<WorkRequest>();


This loads WorkRequestItems with WorkRequest upon execution.

However, the desired outcome is to turn WorkRequest into T
So something like:
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith<T>( //targetChildObject );
dc.LoadOptions = loadOptions;
Table table = dc.GetTable<T>();

T gets passed in from the controller.
loadOptions.LoadWith<T> expects Expression<Func<T, object>> expression as it's argument.

Any help would be appreciated.
Was this page helpful?