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.id
select new
{
p.count
}).ToArray();
in count column have any value,and I want to sum all of the count value. For example:
how can I implant that?thanks.
AVG() SyntaxThe SUM() function returns the total sum of a numeric column.
Items select new { Sum(p. Total), Sum(p. Done)};
Introduction to LINQ Include. LINQ include helps out to include the related entities which loaded from the database. It allows retrieving the similar entities to be read from database in a same query. LINQ Include() which point towards similar entities must read from the database to get in a single query.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With