In this question the answer also had the option of "Or create a class and return list of that instead of using Anonymous type."
Limit Linq result columns for GridView
Could someone show me how to do that?
In this question the answer also had the option of "Or create a class and return list of that instead of using Anonymous type."
Limit Linq result columns for GridView
Could someone show me how to do that?
anonymous type:
var query = (from dins in h.Dinners
where dins.Title == "New York"
select new { dins.Title, dins.DinnerID });
custom type:
public class myType
{
public string Title { get; set; }
public int DinnerID { get; set; }
}
select new { etc }
becomes
select new myType { Title = dins.Title, DinnerID = dins.DinnerID }
You can omit the Title = and DinnerID = IF the property names are the same, but I've included them for clarity