0

i am making a call from SV app to a domain service and waiting to receive IQueryable. In my model i have an one to one relationship with the object UserSession. So in the linq query i am telling that i need an eager loading on UserSession.

return (from u in this.ObjectContext.Users.Include("UserSession") where u.UserId == pUserID
    && u.UserSession != null select u).First<User>(); 

inside the method in the service if i am accessing myUser.UserSession i have the UserSession object but when i receive this object on the Silverlight the myUser.UserSession is null. Why ? It is normal to have this behavior ? I am thinking that is not; because why else i would use relations in EF if i can not use them. On bad workaround is to make 2 calls, one for the user and one for the user session.

Can somebody give me a hint? thank you.

1
  • Do you defined any metadata information for User? Like applying IncludeAttribute to property UserSession?
    – Jehof
    Oct 6, 2011 at 12:36

1 Answer 1

1

Finaly i found an answer thanks to this blog: http://madsdevblog.blogspot.com/2011/02/eager-loading-ef4-entities-with-ria.html.

But for short i was trying to eager load the the User object and in order to do that in EF4 you must do these steps:


Step I. Disable eager loading "1. Double click on your .edmx file in the solution explorer 2. Right click anywhere in the white space and click "Properties" 3. In the properties window, set "LazyLoadingEnabled" to false. You will then see that in the generated file, the following line will be added: this.ContextOptions.LazyLoadingEnabled = false; "


Step II. Use Include in the linq query (step which i already do)


Step III. Add the [Include] attribute to the navigation properties "1. Locate the section where Navigation Properties are set 2. Add [Include] as an attribute beneath the [DataMember()] attribute 3. Add using System.ServiceModel.DomainServices.Server; to the using section in the template. 4. Save and run the template. "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.