I have the following tuple:
Tuple<Expression<Func<Client, object>>, SortOrder>(x => x.ClientLastName, SortOrder.Descending)
In this case I know the entity - "Client" and you are using the "ClientLastName" column.. x => x.ClientLastName.
I want to change this to a generic version where entity is T and I supply the column name using the value keyValue.Key... eg keyValue.Key in this case = "ClientLastName".
I tried this:
foreach (KeyValuePair<string, SortDirection> keyValue in sortItems) {
tupleList.Add(new Tuple<Expression<Func<T, object>>, SortDirection>(x => keyValue.Key, keyValue.Value));
};
Even though T is Client and keyValue.Key is the column name "ClientLastName"
it doesnt work.. It simply comes up with:
It is not replacing the value of keyValue.Key and instead is using the actual value..
saw this answer by sstan in which he used
d => "value" == (string)typeof(Demo).GetProperty(propname).GetValue(d))
which I changed to:
Tuple<Expression<Func<T, object>>, SortDirection>(x => (string)typeof(T).GetProperty(keyValue.Key).GetValue(x), keyValue.Value));
Which didnt work.
How do I do this x => x.keyValue.Key where it replaces the keyValue.Key with its string value and I can have the equivalent of x => x.ClientLastName?

