In Entity Framework, how do you get rid of a circular reference?

.net entity-framework orm

Question

A serialization problem was raised because my Customer and Order entities included a circular reference. Is it possible to have EF create references in just one direction between these two entities? I appreciate it.

1
8
8/13/2015 8:09:24 AM

Accepted Answer

Projecting onto other kinds is what I often do when I need to serialize. Circular references are removed along with any material I don't wish to serialize. For instance:

var q = (from c in Repository.Customers()
         where c.Id == id
         select new 
         {
             Name = c.Name,
             Orders = from o in C.Orders
                      select new
                      {
                          Date = o.Date
                      }
         }).First();
return Json(q);
13
1/21/2010 1:28:17 PM

Popular Answer

By switching the Getter for the Child's navigation property from public to internal, I was able to resolve this issue with EF 3.5.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow