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 ?
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);