LINQ count query returns a 1 instead of a 0

前端 未结 2 1103
无人及你
无人及你 2021-01-22 01:57

I have the following view:-

CREATE VIEW tbl_adjudicator_result_view
AS
SELECT a.adjudicator_id, sar.section_adjudicator_role_id, s.section_id, sdr.section_dance_         


        
相关标签:
2条回答
  • 2021-01-22 02:35

    The point is: you're grouping your data in the LINQ query - and you'll always get at least one group.

    That group's Count may be 0 - but the count of groups will be 1.

    0 讨论(0)
  • 2021-01-22 02:44

    You're not doing the same thing in the LINQ query as in the SQL. COUNT(result_id) does not count distinct values of result_id - it counts non-null values.

    Try this instead:

    Count = grp.Select(p => p.result_id).Where(x => x != null).Count()
    
    0 讨论(0)
提交回复
热议问题