Linq query with nullable sum

前端 未结 14 1881
粉色の甜心
粉色の甜心 2020-11-29 06:23
from i in Db.Items
select new VotedItem
{
    ItemId = i.ItemId,
    Points = (from v in Db.Votes
              where b.ItemId == v.ItemId
              select v.Poi         


        
相关标签:
14条回答
  • 2020-11-29 06:59

    I think this is the same case. I resolved it. This is my solution:

    var x = (from a in this.db.Pohybs
                     let sum = (from p in a.Pohybs
                                where p.PohybTyp.Vydej == true
                                select p.PocetJednotek).Sum()
                     where a.IDDil == IDDil && a.PohybTyp.Vydej == false
                     && ( ((int?)sum??0) < a.PocetJednotek)
                     select a);
    

    I hope this help.

    0 讨论(0)
  • 2020-11-29 07:00

    If you don't like casting to nullabe decimal you could also try using Linq To Objects with ToList() method,

    LinqToObjects Sum of empty collection is 0, where LinqToSql Sum of empty collection is null.

    0 讨论(0)
提交回复
热议问题