tags:

views:

31

answers:

1

Hi all. I want to be able to specify the properties to get populated/updated in the linq expression. Something in the following fashion:

Proxy.UpdateEmployee(List<string> propertiesNames)
Proxy.GetEmployee() //inside the method populate only certain properties

The return values must be of known type(no anonymous types accepted). DLINQ enable to select by specifying properties' names but the result is IQueryable interface and I'm unable to AsEnumerable() it in order to build the known type query afterwards.

A: 

You have to use reflection to modify instance properties by name. So wherever you're updating your object with LINQ you need to do something like this:

foreach (string propName in propertiesNames)
{
    PropertyInfo prop = this.GetType().GetProperty(propName);
    prop.SetValue(valueForProp);
}
Graphain
Thanks for the suggestion.Tried this approach, appears slower and produces unwanted side-effects...
Gena Verdel
What do you mean produces unwanted side effects? Slower than what? It is the only way to modify an object given the string names of the properties to modify.
Graphain