I have this static method in my business layer for returning Dinners
public static System.Collections.Generic.List<Dinner> GetDinners()
{
using (DataClassesDataContext h = new DataClassesDataContext())
{
var query = (from dins in h.Dinners
where dins.Title == "New York"
select dins);
return query.ToList();
}
}
I use this to populate a grid in my aspx page.
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = BusinessLayer.GetDinners();
GridView1.DataBind();
}
I want to limit the returned columns at the business layer level. Which I can do in Linq like this.
var query = (from dins in h.Dinners
where dins.Title == "New York"
select new { dins.Title, dins.DinnerID });
But then I get an anonymous type error, which makes sense, but how do I get around this correctly?
Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to
'System.Collections.Generic.List<Dinner>