Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deserializing Issue in Entity Framework 4.0

I am working on an appliction, using Entity Framework 4.0. and WCF.

I am returning list of objects say (Employees)

and the navigational property of that object is say(Departments)

and Department has further a navigational property (Branch)

I am including everything as

Employees.include("Departments.Branch");

Now th issue all those departments whose Branch is same, is set to null(except the first one) upon deserializing on WCF.

I need to use the branch for some binding purposes, kindly guide me how should i get rid of this problem.

This is the screenshot of the entities enter image description here

like image 671
Manvinder Avatar asked Feb 14 '12 06:02

Manvinder


1 Answers

It may be that the data is not being loaded before serialisation, but when you debug on the server side, lazy loading causes the data to be loaded.

A couple of things that you could try.

This will force the query to run:

Employees.include("Departments.Branch").ToList();

This will explicitly load the entities:

context.Entry(Employees).Reference(u => u.Departments.Branch).Load();
like image 150
Shiraz Bhaiji Avatar answered Sep 21 '22 19:09

Shiraz Bhaiji