I have a query by linq to NHibernate.
var q = SessionInstance.Query<Request>().Max(e => e.Code);
If Request
table has no rows, execution of this query raises GenericADOException with this message :
{"Could not execute query[SQL: SQL not available]"}
{"Value cannot be null.\r\nParameter name: item"}
What should I do?
Try this
SessionInstance.Query<Request>().Max(x => (int?)x.Code);
I think this should work with Linq-to-Nhibernate:
var q = SessionInstance.Query<Request>().Select(e => e.Code)
.DefaultIfEmpty().Max();
or maybe DefaultIfEmpty(<some value>)
.
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