group by using linq c# on entity framework

后端 未结 2 1674
名媛妹妹
名媛妹妹 2021-01-27 02:33

I need to group by Names and to sum all the instance of the name this is my code in the controller:

public class FansController : Controller
{
    private dbFan          


        
2条回答
  •  轮回少年
    2021-01-27 03:06

    see this

    Selecting count in LINQ

    And try something like:

    var group = (from f in db.fans
                group f by a.Name into g
                select new { Name = g.Name, Count = g.Count() });
    

提交回复
热议问题