EF6: How to avoid circular reference?

asp.net-web-api c# entity-framework-6 json

Accepted Answer

Technically speaking, serialising the domain model directly presents no issues. You cannot use lazy loading to prevent circular references. You must maintain command of the loading. So as to

  1. before each collection of your model, delete the virtual (in code first approach)
  2. set lazy loading configuration to false (in database first approach)
6
10/3/2016 5:00:31 AM

Popular Answer

Avoid attempting to directly serialise your domain model. Make a view model that delivers the data in the desired format. Fill up the view model using data from your domain model. Much more information here ViewModels: Why do we use them?



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