The following query expression currently returns the list of CUISINES in the CUISINE table. I would also like to return the COUNT of each number of restaurants offering that cuisine from the RESTAURANT table using the CUISINE_ID field in the RESTAURANT table. I tried using the 'let' but received an error stating that "can't convert lambda expression to type string because it is not a delegate type." Your help would be appreciated. ~susan~
public IEnumerable <string> getCuisines()
{
var cuisineList = fr开发者_运维问答om CUISINE in db.CUISINEs.Include("RESTAURANT")
orderby CUISINE.CUISINE_NAME ascending
select CUISINE.CUISINE_NAME;
return cuisineList;
}
Here you go.
var cuisineList = from x in db.CUISINEs
join y in db.RESTAURANT on x.CUISINE_ID equals y.CUISINE_ID
group x by x.CUISINE_ID into g
select new
{
key = g.Key,
Count = g.Count(),
g
}
You can also refer SQL TO LINQ- Conversion
精彩评论