New Posts New Posts RSS Feed: Problem with the FakeBackingStore (SampleData)
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Problem with the FakeBackingStore (SampleData)

 Post Reply Post Reply
Author
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Topic: Problem with the FakeBackingStore (SampleData)
    Posted: 19-Jun-2012 at 9:26am
Hi marcel,


I found a problem with the manager used for the SampleData.

If during the process of generating my fake data I need to query an entity (exemple : EntityA.Navigation1.FirstOrDefault()), I get an exception in my LoginManager because of the null credential. In cocktail you use an AnonymousLoginAuthentication on this manager but my server doesn't allow anonymous login.
Shouldn't cocktail create an entitymanager with the shouldconnect flag as false (actually it's true) for the manager used to fill the sampledata ? If added  a special connectionOption (the same one as the Fake connectionOption with the shouldConnect to false) in cocktail and use it when the manager created is for the SampleData, all seems fine.




Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 19-Jun-2012 at 9:51am
Why are you attempting to query the data source while setting up the sample data? If you do need to query, query the cache, either by appending ".With(QueryStrategy.CacheOnly)" to your query or setting the manager's DefaultQueryStrategy to CacheOnly. You may have a point, that I probably should create this manager disconnected or at a minimum automatically set the DefaultQueryStrategy to CacheOnly. I'll put that on my list of things to do.
 
Aside from that, though, the EntityManager eventually connects to the BOS to load the sample data into the fake store. In order to do that it needs to login and as you discovered, it uses an anonymous authentication context for that purpose. To make this work, you simply inject a fake login manager on the server when using the fake store. This fake login manager will allow anonymous login. You can see how that is done in TempHire.
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 19-Jun-2012 at 10:04am
I've created a work item to track this issue.
 
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 19-Jun-2012 at 10:09am
when I said "query" I didn't mean an Entityquery but using LINQ on the Navigation properties of an entities.
Something like Customer1.Orders.FirstOrDefault() will fail because it tries to login. but it shouldn't need since all the data are there.

Few month ago I used a FakeLoginManager but not anymore, now I use the normal LoginManager in both case. In the fakestore mode, I needed to be able to use different login with differents role/right on it. 
I probably doesn't do the right things actually but actually, in fakestore mode, everytime I try to login, I first inject the fake logins/roles in the entitymanager to be able to check the credential. I can't rely on a single Fake login, I need to be able to use differents login because the application has differents access rights.



Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 19-Jun-2012 at 10:21am
I see. Yes, accessing a navigation property will lazy load it even if the data is already in the cache. This is because DevForce cannot assume that all related entities are actually in the cache, so it goes to the data source the first time you access the navigation property. This behavior can be changed by setting the DefaultEntityReferenceStrategy on the EntityManager to NoLoad.
 
manager.DefaultEntityReferenceStrategy = EntityReferenceStrategy.NoLoad;
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 19-Jun-2012 at 10:27am
Thanks, that worked.
 
I think this is a common behavior for the sampledata, maybe you could add it in the method ResetFakeBackingStoreAsync ?
 
 
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 19-Jun-2012 at 10:40am

Yes, I will make the change such that EntityQueries and navigations automatically go against the cache.

Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 20-Jun-2012 at 12:39am
Thanks for the fix.
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 20-Jun-2012 at 10:41am
You are welcome.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down