© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
6 replies
WibblyWobbly

❔ 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>();
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith<WorkRequest>(m => m.WorkRequestItems);
dc.LoadOptions = loadOptions;
Table table = dc.GetTable<WorkRequest>();


This loads
WorkRequestItems
WorkRequestItems
with
WorkRequest
WorkRequest
upon execution.

However, the desired outcome is to turn
WorkRequest
WorkRequest
into
T
T

So something like:
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith<T>( //targetChildObject );
dc.LoadOptions = loadOptions;
Table table = dc.GetTable<T>();
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>
loadOptions.LoadWith<T>
expects
Expression<Func<T, object>> expression
Expression<Func<T, object>> expression
as it's argument.

Any help would be appreciated.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Combine two Expression Func [Answered]
C#CC# / help
4y ago
Comparing types when using reflection
C#CC# / help
4y ago
✅ Getting generic type parameters using reflection
C#CC# / help
3y ago