In Linq, how do you write SQL IsNull()?

.net entity-framework linq linq-to-entities wpf

Question

Possible Duplicate:
Equivalent of SQL ISNULL in LINQ?

I am recently migrated from ADO.Net to Entity Framework

I have problem in executing this query in Linq

select IsNull(MAX(InvoiceNo),0) from Sales

I have written this query in LINQ except isNull()

        var q = (from p in dbContext.Sales
                 select p.InvoiceNo).Max();

But i dont know how to use IsNull() in this Linq

When i execute this Linq Query I am getting this exception.

'The invocation of the constructor on type 'JIMS.ViewModel.Transaction.SalesViewModel' that matches the specified binding constraints threw an exception.' Line number '8' and line position '6'.

I am using WPF MVVM FrameWork with Entity FrameWork as DAL

1
3
5/23/2017 12:24:50 PM

Accepted Answer

var InvoiceNo = dbContext.Sales.Max(x => (int?)x.InvoiceNo) ?? 0;
9
3/20/2012 4:53:38 PM

Popular Answer

Try this:

var q = (from p in dbContext.Sales
                 select (int?)p.InvoiceNo).Max();


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