I'm looking to dynamically select fields from a linq query where the fields names are in a csv string.
public IEnumerable<object> GetAllPeople(string fields)
{
return (from p in people
where p.alive == true
select (the csv fields parameter (ie. fields = Name,Age,Height);
}
Yes, I'm using this as sort of a poor mans OData because I can't use OData where I am.
peopleand what exactly do you want to extract fromfields(a specific field, all the fields, ect.)? Off the cuff I would think you can accomplish what you want byfields.split(",")Personbut yourSelect-statement just returns a subset of the properties of aPerson? This won´t work at all, either return aPersonor just parts of it - which would be an anoynmous type which you can´t return effectivly from a method. You might returnIEnumerable<object>, but what are you doing with the instances within that list? You can´t cast them to their actual type as it was anonymous.