开发者

Linq to Entities Lambda expression COUNT

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜