Selecting count in LINQ

后端 未结 4 980
忘掉有多难
忘掉有多难 2021-01-14 00:50

I got a SQL Server table with columns ResolvedDate and ResolvedBy.

Now I want to select those two columns and count their results, which I

4条回答
  •  孤街浪徒
    2021-01-14 01:02

    var dates = dataContext.Activities
        .Where(a => a.IsResolved && a.ResolvedBy == userId)
        .Select(a => a.ResolvedDate)
        .ToList();
    
    var count = dates.Count;
    

    If you only want to get the count, you can make it much faster by selecting the count alone:

    var count = dataContext.Activities
        .Count(a => a.IsResolved && a.ResolvedBy == userId);
    

提交回复
热议问题