I have a Linq to Entities query like this one:
var results = from r in entities.MachineRevision where r.Machine.IdMachine == pIdMachine && r.Category == (int)pCategory select r;
Usually, I use the code below to check if some results are returned:
if (results.Count() > 0) { return new oMachineRevision(results.First().IdMachineRevision); }
However, I’m getting NotSupportedException in the if condition.
The error message is: Unable to create a constant value of type ‘Closure type’. Only primitive types (‘such as Int32, String, and Guid’) are supported in this context.
Note that pCategory is an Enum type.
EDIT: Based on your update, the error may be related to an enum in your entity class. See this blog entry for more information and a work-around. I’m leaving my original answer as an improvement on your query syntax.
Try doing the selection of the first entity in the query itself using FirstOrDefault and then check if the result is null.