New Posts New Posts RSS Feed: Error with Multiple Instances of EntityQueryPagedCollectionView
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Error with Multiple Instances of EntityQueryPagedCollectionView

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

Joined: 20-Aug-2010
Location: Tallahassee, FL
Posts: 11
Post Options Post Options   Quote EisenbergEffect Quote  Post ReplyReply Direct Link To This Post Topic: Error with Multiple Instances of EntityQueryPagedCollectionView
    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:




Edited by EisenbergEffect - 03-Sep-2010 at 9:14am
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post 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? 
Back to Top
EisenbergEffect View Drop Down
Newbie
Newbie
Avatar

Joined: 20-Aug-2010
Location: Tallahassee, FL
Posts: 11
Post Options Post Options   Quote EisenbergEffect Quote  Post ReplyReply Direct Link To This Post Posted: 02-Sep-2010 at 11:28am
Where? I can't see where to assign such a value.
Back to Top
WardBell View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 31-Mar-2009
Location: Emeryville, CA,
Posts: 338
Post Options Post Options   Quote WardBell Quote  Post ReplyReply Direct Link To This Post 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 :-)
Back to Top
EisenbergEffect View Drop Down
Newbie
Newbie
Avatar

Joined: 20-Aug-2010
Location: Tallahassee, FL
Posts: 11
Post Options Post Options   Quote EisenbergEffect Quote  Post ReplyReply Direct Link To This Post 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?
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: 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.
Back to Top
EisenbergEffect View Drop Down
Newbie
Newbie
Avatar

Joined: 20-Aug-2010
Location: Tallahassee, FL
Posts: 11
Post Options Post Options   Quote EisenbergEffect Quote  Post ReplyReply Direct Link To This Post Posted: 03-Sep-2010 at 9:13am
Thanks for the work around. I just confirmed that that will work for us.
Back to Top
WardBell View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 31-Mar-2009
Location: Emeryville, CA,
Posts: 338
Post Options Post Options   Quote WardBell Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down