Reputation: 117
I have this linq query
(from diference in General.db.PTStbDifferenceByMonths
join list in General.db.PTStbLists on new
{
month = diference.ListMonth,
year = diference.ActiveYear,
national = diference.NationalCode,
shobe = diference.BranchCode
}
equals new
{
month = list.Month,
year = list.Year,
national = list.NationalCode,
shobe = list.ShobeCode
}
join hoghoughList in General.db.PTStbhogogMomayezs on new
{
melliCode = diference.MelliCode,
national = diference.NationalCode,
shobe = diference.BranchCode,
serial = list.Id
}
equals new
{
melliCode = hoghoughList.MelliCode,
national = hoghoughList.NationalCode,
shobe = hoghoughList.ShobeCode,
serial = hoghoughList.SerialList
}
join karmand in General.db.PTStbKarkonans on
hoghoughList.MelliCode equals karmand.MelliCode
where diference.ListMonth == activeMonth && diference.ActiveYear == activeYear &&
diference.NationalCode == id && diference.BranchCode == branchCode
select new ReturnedDifference
{
Maliat = hoghoughList.FinalTax,
ComputedMaliat = diference.ComputedMaliat,
ComputedMoghayerat = diference.ComputedMoghayerat,
hoghough = (hoghoughList.NGPTotalDaramadeMashmol ?? 0),
ListId = diference.ListMonth,
MelliCode = karmand.MelliCode,
LastName = karmand.Family,
Name = karmand.Name,
PayedTax = diference.PayedTax,
ActualPayedTax = hoghoughList.FinalTax
}).OrderBy(l => l.MelliCode);
I want to sum hoghoughList.NGPTotalDaramadeMashmol and group by by other fields but hoghoughList.NGPTotalDaramadeMashmol didn't have Sum function because it's nullable long. is it a way to sum this value and group by other fields?
Upvotes: 0
Views: 128
Reputation: 1730
You can use the coalesce ??
to treat the nullable as 0:
.Sum(v => (v.hoghoughList.NGPTotalDaramadeMashmol ?? 0))
Upvotes: 1