linq2db / linq2db.EntityFrameworkCore

Bring power of Linq To DB to Entity Framework Core projects
MIT License
462 stars 38 forks source link

in code it's decimal,but in sqlserver it can be null ,how to solve #12

Closed quan01994 closed 5 years ago

quan01994 commented 5 years ago
 var qry =
        from dQry in depositQry
        from qry1 in (from cQry in consumeQry
                        from oiQry in orderQry.FullJoin(m => m.GoodsBrandCode == cQry.GoodsBrandCode)
                        select new { cQry, oiQry })
            .FullJoin(m => m.oiQry.GoodsBrandCode == dQry.GoodsBrandCode)
        group new { qry1, dQry } by qry1.oiQry.GoodsBrandCode into g 
        select new GoodsBrandAnalysisOutput
        {
            SaleAmout = g.Sum(m => m.qry1.oiQry.SaleAmout  - m.qry1.cQry.ConsumeAmout + m.dQry.DepositAmount),
            GoodsBrandCode = g.Key,
            SaleQnty = g.Sum(m => m.qry1.oiQry.SaleQnty - m.qry1.cQry.ConsumeQty + m.dQry.DepositQty)
        };

m.qry1.cQry.ConsumeAmout may be is NULL in sqlserver but m.qry1.cQry.ConsumeAmout in code is decimal not decimal? how to set m.qry1.cQry.ConsumeAmout default is 0;

/*i want like this*/
ISNULL(m.qry1.cQry.ConsumeAmout,0)
sdanyliv commented 5 years ago

Are you looking for such technique?

Sql.ToNullable(m.qry1.cQry.ConsumeAmout) ?? 0
quan01994 commented 5 years ago

let me try it out.

quan01994 commented 5 years ago

thank you, 👍

sdanyliv commented 5 years ago

I see, you become more powerful linq query writer :) Even i have developed FullJoin support, i have never used it in real projects ))