How can I calculate sum of column value in linq to sql query?

前端 未结 1 1425
予麋鹿
予麋鹿 2021-01-12 13:54

I\'m write this query:

var query2 = (from p in behzad.Compare_closed_numbers_in_CRM_and_Billing_system_detail_counters
               where p.fileid == point         


        
相关标签:
1条回答
  • 2021-01-12 14:53

    If count field is int try this:

    int sum = behzad.Compare_closed_numbers_in_CRM_and_Billing_system_detail_counters
         .Where(t=>t.fileid == point.id)
         .Select(t => t.Count ?? 0).Sum();
    

    If count field is nvarchar(max) try this:

    int sum = behzad.Compare_closed_numbers_in_CRM_and_Billing_system_detail_counters
             .Where(t=>t.fileid == point.id)
             .Select(t => Convert.ToInt32(t.Count)).Sum();
    
    0 讨论(0)
提交回复
热议问题