2

I have a graph of objects :

School-->Classes-->Students.

and I want to set it up in a way that I can send back school class to the client and it can access classes and students in a lazy-loading way.

is that possible ?

2 Answers 2

5

In brief: no.

You can either :

  • send back all the data needed (including classes and students with your school entity) in a single call ("eager loading")

or:

  • you need have to have separate methods on your WCF service to retrieve detail data in a separate call (something like: List<Class> GetClassesForSchool(int schoolId), List<Student> GetStudentsForClass(int classId))

Lazy loading per se only works as long as your Entity Framework object context is still around to be queried for more data - which is certainly not the case when you send entities across the wire using WCF.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 Implicit lazy loading over web service is bad architecture and hard to achieve (you must implement it by yourselves in client entity properties). You must do what @marc described or you can use WCF Data services which supports Expand method for explicit loading of navigation properties.
2

I don't think so, because your entity is travelling across different tiers and the one with database connection won't be accessed without your interventation from any other tier.

You'll need to tailor your own solution to do that, or just use data-transfer objects, which will have the right information nor the one that may be useless for some view.

Update: Read this article if you want to learn more about DTO pattern:

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.