I am working with MongoDb and at some point, I am needing to create a lambda expression as follows:
...Set(g => g.Profile.First_Name, "Test");
Now, g
refers to a class called User
, which has a property of type Profile
(a different class), with the same name Profile
. As you can see, in the lambda expression, I am selecting the First_Name
property and then passing the value "Test"
to it. My question is, is there a way I can select the property with the property's name itself?
I mean, is something like this possible?
.... g.Profile. ("First_Name")
As I am typing this, even to me it sounds ridiculous, but I need to dynamically select the particular properties, so I need to select them via their names. How do I actually achieve this?
I tried:
g.Profile.GetType().GetProperty("First_Name")
But it doesn't seem to be equivalent to g.Profile.First_Name
. Any ideas on what can be done?
Aucun commentaire:
Enregistrer un commentaire