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
var InvoiceNo = dbContext.Sales.Max(x => (int?)x.InvoiceNo) ?? 0;
Try this:
var q = (from p in dbContext.Sales
select (int?)p.InvoiceNo).Max();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With