I’m confused about the way LINQ works within PreprocessQuery. I’ve been troubleshooting a problem with a larger query for a custom search screen. The rest of the query seems to work except for one small part that I’ve finally isolated:
query = query.Where(i => i.IntValue == 100);
This returns no results, even though the database clearly has values that match.
However, the following does work:
query = query.Where(i => i.StringValue == "value");
There aren’t any calculated fields involved, which I’ve seen issues with before. What am I missing?
In this particular case, it turned out that I had remnants of a query that had been built using the Lightswitch query designer. Both queries can coexist and complement each other, but (as in this case) they can also interfere. After clearing out the query from the designer, my code-based query worked great.
For future reference, if you start off with a query in the designer, and decide to switch, you should remember to clean out the stuff in the designer. In the Lightswitch forum post, Yann mentioned that he always defaults to building the query in code, which is probably a pretty good idea if you have anything more than the simples of queries.