Print Page | Close Window

Error with Multiple Instances of EntityQueryPagedCollectionView

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2116
Printed Date: 19-Sep-2025 at 11:02am


Topic: Error with Multiple Instances of EntityQueryPagedCollectionView
Posted By: EisenbergEffect
Subject: Error with Multiple Instances of EntityQueryPagedCollectionView
Date Posted: 02-Sep-2010 at 9:13am
We are trying to use two instances of EntityQueryPagedCollectionView simultaneously. There appears to be an internal problem with this related to the queries not having different UserState values. Is there any way to work around this? Below is a screen cap of our error dialog:





Replies:
Posted By: smi-mark
Date Posted: 02-Sep-2010 at 11:27am
Are you currently using a userstate? If not, why not just throw in a Guid.NewGuid() as the userstate? 


Posted By: EisenbergEffect
Date Posted: 02-Sep-2010 at 11:28am
Where? I can't see where to assign such a value.


Posted By: WardBell
Date Posted: 02-Sep-2010 at 7:25pm

Hi Rob - Going to need a little more than this to understand the issue.

Btw, there is one "UserState" object for the entire task chain ... and you supply it as an optional argument to Execute when you kick off the task chain.
 
I'm sorry this is not well documented. In fact, the entire section on it is missing from the DRC (DevForce Resource Center). It was never that great to begin with but we want to fill the gap soon.
 
So, Rob, can you show us some code :-)


Posted By: EisenbergEffect
Date Posted: 03-Sep-2010 at 7:51am
The code is pretty simple. I am not actually executing the queries myself. That is being done by the EntityQueryPagedCollectionView


              var query = manager.AdmissionApplications
                    .Where(x => x.Review.Status.IsInitialStatus && x.IsSubmitted)
                    .OrderBy(x => x.SubmittedAt)
                    .Include(x => x.PersonalInformation)
                    .Include(x => x.PersonalInformation.Account)
                    .Include(x => x.Requirements)
                    .Include("Requirements.Requirement");

                Applications = new EntityQueryPagedCollectionView(
                    (EntityQuery)query,
                    PageSize
                    );

                var query2 = manager.Inquiries
                    .Where(x => x.IsSubmitted && x.Status == InquiryStatus.New)
                    .OrderBy(x => x.SubmittedAt)
                    .Include(x => x.PersonalInformation);

                Inquiries = new EntityQueryPagedCollectionView(
                    (EntityQuery)query2,
                    PageSize
                    );

In this case, both Applications and Inquiries are instances of EntityQueryPagedCollectionView. This code causes the above error to occur. As far as I can tell, there is no way to set the UserState since I am not directly executing the queries. Is this a bug in the CollectionView or am I missing something entirely?


Posted By: kimj
Date Posted: 03-Sep-2010 at 9:07am
This is a bug in the EntityQueryPagedCollectionView.  When it creates a query for a page it uses the page number as the "UserState" for the async query for tracking purposes.  The internal tracking for async queries done via the EntityManager disallows using the same UserState twice at one time, so because you're using two EntityQueryPagedCollectionView instances with one EntityManager you've run into the problem.  We'll add a bug report to fix this.  The workaround for now would be to use a separate EntityManager with each EQPCV.


Posted By: EisenbergEffect
Date Posted: 03-Sep-2010 at 9:13am
Thanks for the work around. I just confirmed that that will work for us.


Posted By: WardBell
Date Posted: 03-Sep-2010 at 1:46pm
Remember to instantiate each new EntityManager using the prior one so that you can carry over the authentication information from one EM to the next.  For example:
 
  var aNewManager = new NorthwindEntitiesManager(existingManager);
 
The other way to do this - a way that ONLY associates the managers by authentication - and perhaps the preferred way these days - is: 
 
  var aNewManager = new NorthwindEntitiesManager();
  aNewManager.LinkForAuthentication(existingManager);

Merely writing "new NorthwindEntitiesManager()" will cause the new manager to login when used. You might not notice if you haven't implemented a LoginManager but you'll be thrashing the login process.
 
I often keep a root EntityManager in a safe place just so I can mint new EntityManagers.



Print Page | Close Window