Similarly: Convert string to Linq.Expressions or use string as a selector?
Similar to one: Passing a Linq expression as a string?
Another question with the same answer: How to create a dynamic Linq expression based on lambda from a string in C #?
Reason for asking for something that has so many similar questions:
The accepted answer in such questions is unacceptable, since they all refer to the library from 4 years ago (provided that it was written by code wizard Scott Gu), written for the old structure (.net 3.5) and does not provide anything but a link as an answer .
There is a way in the code to do this without including the whole library.
Here is a sample code for this situation:
public static void getDynamic<T>(int startingId) where T : class { string classType = typeof(T).ToString(); string classTypeId = classType + "Id"; using (var repo = new Repository<T>()) { Build<T>( repo.getList(), b => b.classTypeId
Note that this does not look to turn an entire string into an expression such as
query = "x => x.id == somevalue";
But instead, it tries to use only the string as access
query = x => x.STRING;
generics c # linq asp.net-mvc-3
Travis j
source share