I have a class property name as string variable and want to use that in LINQ query. Below example:
public class Demo
{
public string prop1 {get; set;}
public string prop2 {get; set;}
public string prop3 {get; set;}
}
I can do this
var data = db.Single<Demo>(d => d.prop1 == "value");
But don't know what's the property is at runtime and getting that string parameter like
string propname = "prop2";
Is there any possibility to use that in lambda expression d => d.propname == "value"? I am not sure it can be and logically doesn't seem possible. so thought of posting a question and see if there is a way. Please suggest.
To Note, that Single() call is happening over MongoDB C# Driver and thus not sure whether reflection would work.