I would like to have some flexibility and provide some interface to specify list of columns that should be included to the final select dynamically.
For example for this table
public class Person
{
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity), Key()]
public int Id { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
public string Address { get; set; }
...
}
I want to have at one case
persons.Select(p => new { FirstName = p.FirstName, LastName = p.LastName }).ToList();
but at another I want to have
persons.Select(p => new { FirstName = p.FirstName, LastName = p.LastName, Address = p.Address }).ToList();
at third case I'll need something else... So, I was thinking it would be good to have some flexible mechanism that would allow to specify the list of columns to extract.
Any ideas how I can do this?
I was reading a bit about LINQ expressions and I have some feeling that this is the right way but do not understand how implement it yet...