New Posts New Posts RSS Feed: Silverlight EntityManager Returns No Results
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Silverlight EntityManager Returns No Results

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

Joined: 13-Mar-2009
Location: Olympia, WA
Posts: 8
Post Options Post Options   Quote NotMyself Quote  Post ReplyReply Direct Link To This Post Topic: Silverlight EntityManager Returns No Results
    Posted: 02-Apr-2009 at 4:59pm

I have a solution that I built from the ground up today after installing DevForce SL RC1 that I downloaded today. The solution looks like this:

 
Projects located in the Domain folder were generated using the object mapper and are the standard setup described in the developers guide section "Hello, DevForce". The only modifications I have made are changes to the assembly names to make them more meaningfull.
 
CaseManager.Console is a simple console app with this code. It successfully prints 3 records and I can see queries running via profiler.
 
CaseManager.Tests is a Silverlight Unit Test assembly containing this code.  The second test fails every time. No results are returned from the Notes collection. Which is incorrect as the console app returns 3 records. I do not get any errors nor do I see any activity on the database via profiler.
 
What are the other options for troubleshooting this issue? Is there a way to verify that the silverlight application is successfully connecting to EntityService.svc located in CaseManager.Web?
 
 
 
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-Apr-2009 at 9:11am
In DevForce Silverlight, all fetches that retrieve data from the back end (via the EntityService) must be done asynchronously.  So, here _manager.Notes.ToList() is really a synchronous call to the EntityManager cache, and returns no data because nothing is available in cache.  You will need to use an asynchronous fetch, something like _manager.ExecuteQueryAsync<Notes>() to retrieve these entities from the back end.  You'll also need to use a "logged in" EntityManager, which means that a LoginAsync() call must be done first. 
 
The need for asynchronous service calls makes unit testing within Silverlight quite tricky, so it's probably better to first determine whether you need to unit test the service calls or can mock that part.  If unit testing the service is not necessary, it's easiest to load a saved EntityCacheState into an EntityManager and then perform the usual synchronous fetches.
 
When unit testing the service calls is necessary, you also need to mark test methods as [Asynchronous] and use the Enqueue* calls provided by the unit test framework.
Back to Top
NotMyself View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Mar-2009
Location: Olympia, WA
Posts: 8
Post Options Post Options   Quote NotMyself Quote  Post ReplyReply Direct Link To This Post Posted: 03-Apr-2009 at 9:18am
I made some progress on this this morning. My test class now looks like this. I still get no items returned form my query. I want to confirm my understanding of the relationship between the 3 libs I have created using DevForce.
 
 
The CaseManager.DomainModel.Server project holds only the EF generated ServerModel.edmx as well as an app.config containing bascially a connection string. The DevForce Object Mapper generates a second project that I have called CaseManager.DomainModel.Client.
 
Is the role of the assembly containing the EF edmx file only to generate the second assembly?
Do I need to deploy it ot my web that hosts the EntityService.svc?
 
Currently when I build I get this warning:
 
 
What assembly does it expect to have that name? Could this be why I an unable to fetch data?
 
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-Apr-2009 at 10:19am
Re the test class - 1) I would not use DefaultManager, since that static property will perform an automatic connect (which you can't listen for).  Instead always new up a DomainModelEntityManager explicitly.  2) If you're using the SL unit test framework from Microsoft your test methods will also need the [Asynchronous] attribute,  and async actions must be queued using Enqueue* calls.   See http://www.jeff.wilcox.name/2009/03/asynchronous-testing/  for more information.
 
The role of the assembly holding the EDMX is just to hold the Entity Model, and isolate the Entity Framework pieces to one spot.  Having the entity model in a separate assembly is not a requirement.   This assembly must be deployed to the web that hosts the EntityService.
 
Currently, fully-qualified type names in your domain model must exactly match between the Silverlight domain model assembly and the "standard" domain model assembly, which means that the assembly names must also exactly match.   Here those projects would be CaseManager.DomainModel.Client.SL and CaseManager.DomainModel.Client and they should both have the same assembly name.  Usually the Object Mapper will try to ensure that the assembly names for the "Domain Model Project" and "Silverlight Project" choices are kept in sync, so also double check that these drop downs are populated correctly in the OM.  You can also view the project properties in VS to see the assembly name setting, and modify as needed to ensure they're the same for these projects. 
 
 
Back to Top
NotMyself View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Mar-2009
Location: Olympia, WA
Posts: 8
Post Options Post Options   Quote NotMyself Quote  Post ReplyReply Direct Link To This Post Posted: 03-Apr-2009 at 11:35am
Thanks for the info kimj, I'll let you know how it turns out.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down