I have an EF6 data access context that seems to work. There is one that returns cannot evaluate the expression. This is FirstOrDefault. If I execute the query without FIrstOrDefault, IEnumerable contains 1 element that I am looking for. Where am I going wrong? I have many other FirstOrDefaults that work great.
var a = "";
var products = from p in _db.Products
where p.SKU == isbn
select p;
foreach (var productx in products)
{
a = productx.SKU; <- productx contains the valid product
}
var product = (from p in _db.Products
where p.SKU == isbn
select p).FirstOrDefault(); <-- can't evaluate
The same thing happens even if I update the context ....
Both return the correct string in LinqPad ...
Products.FirstOrDefault(p=>p.SKU == "9781250033697")
(from p in Products where p.SKU == "9781250033697" select p).FirstOrDefault()
They give null in my application (isbn = "9781250033697")
var product = _db.Products.FirstOrDefault(p=>p.SKU == isbn);
var products = from p in _db.Products
where p.SKU == "9781250033697"
select p;
Other Ling requests against the same db give valid data.
source
share