EF return null for some but EF Core return 0

asp.net-core-mvc asp.net-mvc c# entity-framework entity-framework-core

Question

I migrate a site ASP.NET MVC to ASP.NET MVC core, with EF to EF Core.

I make a request with empty value :

 var q = bd.Prod
           .Where(o => o.xxx == yyy)
           .GroupBy(o => o.sss)
           .Select(g => new
           {
               ccc = g.Key,
               vvv = g.Sum(i => i.qqq),
               bbb = g.Sum(i => i.fff),
               nnn = g.Sum(i => i.ggg),
           });

When I execute this code with EF return null when all cell of sum are empty. But EF Core return 0 when all cell of sum are empty. How to make EF Core return null ?

1
2
6/13/2017 1:20:44 PM

Popular Answer

Use DefaultIfEmpty:

var q = bd.Prod
          .Where(o => o.xxx == yyy)
          .GroupBy(o => o.sss)
          .Select(g => new
          {
            ccc = g.Key,
            vvv = g.Sum(i => i.qqq),
            bbb = g.Sum(i => i.fff),
            nnn = g.Sum(i => i.ggg),
         })
          .DefaultIfEmpty(null);
1
6/13/2017 10:19:07 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow