New Posts New Posts RSS Feed: Cannot execute query against cache
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Cannot execute query against cache

 Post Reply Post Reply
Author
JeeZ View Drop Down
Newbie
Newbie


Joined: 14-Nov-2007
Location: Canada
Posts: 10
Post Options Post Options   Quote JeeZ Quote  Post ReplyReply Direct Link To This Post Topic: Cannot execute query against cache
    Posted: 27-Apr-2010 at 6:44pm
Hi everybody,

Here's the query I'm trying to execute :

query = _manager.Customers.Where(p => 
                    p.CompanyName.Contains(_searchKeyword)
                        ||
                    p.ContactName.Contains(_searchKeyword)
                        ||
                    p.ContactTitle.Contains(_searchKeyword)
                        ||
                    p.City.Contains(_searchKeyword)
                        ||
                    p.Country.Contains(_searchKeyword)
                        ||
                    p.Region.Contains(_searchKeyword)
                        ||
                    p.Phone.Contains(_searchKeyword)
                        ||
                    p.Fax.Contains(_searchKeyword)
                    );

Here's the exception :
Execution of query against the server was successful but execution of query against the local cache failed


Why?

Note: In a C# WinForm Application, on NorthwindIB database, DevForce Universal Express.
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Posted: 29-Apr-2010 at 5:26pm
That should work.  We're going to run some tests and will let you know what we find.
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 29-Apr-2010 at 6:54pm
Originally posted by JeeZ


query = _manager.Customers.Where(p => 
                    p.CompanyName.Contains(_searchKeyword)
                        ||
                    p.ContactName.Contains(_searchKeyword)
                        ||
                    p.ContactTitle.Contains(_searchKeyword)
                        ||
                    p.City.Contains(_searchKeyword)
                        ||
                    p.Country.Contains(_searchKeyword)
                        ||
                    p.Region.Contains(_searchKeyword)
                        ||
                    p.Phone.Contains(_searchKeyword)
                        ||
                    p.Fax.Contains(_searchKeyword)
                    );



Nice that you were using the NorthwindIB database: that made debugging this a bunch easier, since I have not only the same schema but virtually the same data to test with.

Your query fails because the columns Region and Fax have nulls in them, and .Contains() isn't defined on a null in LINQ. (The query against the server succeeds because EF translates it to SQL that works.)

If your copy of NorthwindIB is like mine, you'll also find two records that have nulls in some of the other columns besides Region and Fax; but those two records have nulls in all of the columns on which you're doing the test, so they don't meet the condition you've posed and are never brought down to the client. Therefore they don't cause the query to fail when it's run on the client!

THE FIX

You can make your query work by changing the syntax of your tests to the following:


                    (p.Region ?? "").Contains(_searchKeyword)


That converts any null to an empty string before executing the Contains test.

As it so happens, we had already changed DevForce (I now know) to do the above translation automatically; so as of the next release, the syntax you used to begin with will work. But you'll need the above syntax for now.

Back to Top
JeeZ View Drop Down
Newbie
Newbie


Joined: 14-Nov-2007
Location: Canada
Posts: 10
Post Options Post Options   Quote JeeZ Quote  Post ReplyReply Direct Link To This Post Posted: 30-Apr-2010 at 4:31am
Thanks Greg! I'll try that and get back to you next week if it doesn't work (but I'm confident it will).

Have a nice week-end!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down