New Posts New Posts RSS Feed: Not able to query locally cached data
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Not able to query locally cached data

 Post Reply Post Reply
Author
AdamC View Drop Down
Newbie
Newbie
Avatar

Joined: 04-Feb-2008
Location: United States
Posts: 20
Post Options Post Options   Quote AdamC Quote  Post ReplyReply Direct Link To This Post Topic: Not able to query locally cached data
    Posted: 16-Jul-2009 at 3:14pm
Hi,

I'm not able to retrieve data I've cached locally.  The second block of code (below) works fine when I am connected to the database.  However, when I am not connected to the database I get a "Sequence contains no elements" error.  The stack trace is at the bottom.

Here is the code used to save the cache state (seems to work fine):

        EntityQuery<LOCAL_STRING> localStringQuery = null;

        localStringQuery =
            (from ls in domainEntityManagerService.DomainEntityManager.LOCAL_STRING
            select ls);

        domainEntityManagerService.DomainEntityManager.CacheStateManager.SaveCacheState("c:\localization.bin");


Here is the code used to query the table/cache.  The RestoreFromCache() method works fine -- it is the line in red throwing the exception.  I may be going about this the wrong way, so hopefully someone can't point me in the right direction.  Is it not possible to use LINQ queries against locally cached data?  Thanks!

        private EntityQuery<LOCAL_STRING> localStringQuery = null;
        public object GetValue(string localKey)
        {
            try
            {
                if (domainEntityManagerService.DomainEntityManager.IsConnected == false &&
                    domainEntityManagerService.DomainEntityManager.IsLoggedIn == false)
                {
                    domainEntityManagerService.DomainEntityManager.DefaultQueryStrategy = QueryStrategy.CacheOnly;
                    domainEntityManagerService.DomainEntityManager.CacheStateManager.RestoreCacheState("c:\localization.bin");
                }

                localStringQuery =
                    (from ls in domainEntityManagerService.DomainEntityManager.LOCAL_STRING
                     where ls.LOCAL_KEY == localKey
                     select ls);

                return localStringQuery.First().LOCAL_TEXT;
            }
            catch ( Exception ex )
            {
                 ...
            }
            return null;
        }



"   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)\r\n   at lambda_method(ExecutionScope )\r\n   at System.Linq.EnumerableExecutor`1.Execute()\r\n   at System.Linq.EnumerableExecutor`1.ExecuteBoxed()\r\n   at System.Linq.EnumerableQuery`1.System.Linq.IQueryProvider.Execute(Expression expression)\r\n   at IdeaBlade.EntityModel.v4.EntityQuery`1.ExecuteCacheQuery(Guid queryGuid)\r\n   at IdeaBlade.EntityModel.v4.EntityQueryFinder.ExecuteFind(Guid queryGuid)\r\n   at IdeaBlade.EntityModel.v4.EntityQueryFinder.Execute()\r\n   at IdeaBlade.EntityModel.v4.EntityManager.ExecuteQueryCore(IEntityQuery query, Boolean isAsync)\r\n   at IdeaBlade.EntityModel.v4.EntityManager.ExecuteQueryForObject(IEntityQuery query)\r\n   at IdeaBlade.EntityModel.v4.EntityQuery`1.System.Linq.IQueryProvider.Execute[TResult](Expression expression)\r\n   at System.Linq.Queryable.First[TSource](IQueryable`1 source)\r\n   at Jenzabar.EX.Infrastructure.Localization.LocalizationProvider.GetValue(String localKey) in C:\\Documents and Settings\\...\\LocalizationProvider.cs:line 79"
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 16-Jul-2009 at 7:00pm
My guess is that nothing was saved to cache initially, or at least not what you expected.  I'm confused by the block of code used to save cache state - you declare a query and then save cache, but the query has not yet been executed. 
Back to Top
AdamC View Drop Down
Newbie
Newbie
Avatar

Joined: 04-Feb-2008
Location: United States
Posts: 20
Post Options Post Options   Quote AdamC Quote  Post ReplyReply Direct Link To This Post Posted: 17-Jul-2009 at 7:16am
Thanks Kim -- I had not yet executed the query.  Now I feel a little silly.  :-)  I had removed an earlier query and subsequent execution code but never added it back.  I was seeing the cache file being created, but now I realize it doesn't mean actual data was saved.  I think that's what hung me up.  Looking at the cache file in a text editor with and without data shows a big difference.  Thanks again.

For anyone interested in what I changed, please see the line in red:


EntityQuery<LOCAL_STRING> localStringQuery = null;

localStringQuery =
    (from ls in domainEntityManagerService.DomainEntityManager.LOCAL_STRING
    select ls);

localStringQuery.Execute<LOCAL_STRING>();

domainEntityManagerService.DomainEntityManager.CacheStateManager.SaveCacheState("c:\localization.bin");

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down