Reformulating EF4 query to avoid parsing error?
How can I reformulate an Entity Data Model query to work around a parsing error? Here is the query:
var selectedNotes = notes
.Where(n => n.Tags.Count == 0)
And here is the exception that is being thrown:
There was an error parsing the query. [ Token line number = 12,Token line offset = 53,Token in error = AS ]
Here is the background to my problem:
I am working on an app that uses Entity Framework 4. The app organizes rich-text documents, called Notes, which are searchable by Tags, like blog entries. One of my Entity Data Model queries retrieves only Notes that have no Tags:
searchResults = DataStore.ObjectContext.Notes.WhereContainsNoTags();
WhereContainsNoTags()
is written as a LINQ extension method, and it contains the lambda expression for the query:
public static IQueryable<Note> WhereContainsNoTags(this IQueryable<Note> notes)
{
IQue开发者_如何学JAVAryable<Note> results;
// Select Notes that contain no search Tags
var selectedNotes = notes
.Where(n => n.Tags.Count == 0)
.OrderBy(n => n.Title);
results = selectedNotes;
// Set return value
return results;
}
For simplicity, I have omitted the try-catch block that wraps the lambda expression and the logging code that logs any errors.
Here is the odd part: The query runs fine on my development machine, but it throws the above exception on the test machine. I have several other queries (match all Tags, match any Tags, and so on) that run fine on both the development and test machines.
I am quessing that the exception relates to the SQL generated by the EDM query. Is that the case? What is the best workaround? Is there a way to reformulate the lambda expression to avoid the problem?
Thanks for your help.
var selectedNotes = notes.Where(n => !n.Tags.Any())
精彩评论