I need the following C# code to be translated to a valid Entity Framework 6 expression:
(f => f.GetType().GetProperty(stringParamter).GetValue(f).ToString() == anotherStringParameter)
This guy did it for the "Order By" part, but i cant seem to figure it out for the "where" part...
Generically speaking what i am trying to achieve here is a form of dynamic query where the user will "pick" properties to filter in a "dropbox", supply the filter-value and hit query... usually people do like f => f.TargetProp == userValue
but i can't do that when i dont know which one it is...
Have you considered using the Dynamic Link Library? It allows you to compose expressions as strings instead of lambda expressions.
Examples:
I've been keeping an updated version of Microsoft's Dynamic Linq example at https://github.com/NArnott/System.Linq.Dynamic in case you are interested, and it's also available on NuGet.
You need to construct the expression tree that represents the access to the property:
This allows you to write: