I have just updated to using EF 4.0 where before i was using Linq 2 SQL.
I have a query:
var UserList = this.repository.GetUsers();
return Json(UserList, JsonRequestBehavior.AllowGet);
This was generating an error: “A circular reference was detected while serializing an object of type“
This prompted this code which worked fine in L2S:
var UserList = this.repository.GetUsers();
foreach (User u in UserList){
u.Subscriptions = null;
}
return Json(UserList, JsonRequestBehavior.AllowGet);
How can i stop EF from looking into the Subscriptions table, i just want the Userlist, none of the related properties and the above example does not seem to work for this.
Cheers,
Kohan
Project your UserList before you pass it to the Json serializer so that it doesn’t dive into any of the EF generated properties.