I have a conditional statement that evaluates an .Any()
LINQ query against my DB.
It is throwing an error when casting/converting a string to long value.
(long.TryParse(m.Reference,out t)? t : long.MaxValue)
The error is something like:
LINQ to Entities does not recognize the method '....' method, and this method cannot be translated into a store expression
Am I doing something wrong here? How can I achieve this?
using (var ctx = new DatabaseEntities())
{
long t;
if(!ctx.CustomerInboxes.Any(m=>m.CustomerId == customerId
&& m.Reference == item.ShoppingCartWebId.ToString()
&& m.SubjectId == HerdbookConstants.PendingCartMessage
&& item.ShoppingCartWebId > (long.TryParse(m.Reference,out t)? t : long.MaxValue)))
)){
// do something special
}
}
m.Reference == item.ShoppingCartWebId.ToString()
anditem.ShoppingCartWebId > (long.TryParse(m.Reference,out t)? t : long.MaxValue)
be true at the same time.