MVC 4, Upshot entities cyclic references

扶醉桌前 提交于 2019-11-29 12:52:32

try decorating one of the navigation properties with [IgnoreDataMember]

[IgnoreDataMember]
public virtual ICollection<Equipment> Equipment { get; set; } 
Szilard Muzsi

The model generated by upshot can be found on the page itself. In your Index view you will see the UpshotContext HTML helper being used (given that you are using the latest SPA version), in which the dataSource and model type are specified.

When the page is then rendered in the browser, this helper code is replaced with the actual model definition. To see that, view the source code of your page in the browser and search for a <script> tag that starts with upshot.dataSources = upshot.dataSources || {};

Check here for more info about how upshot generates the client side model. As for the "backtracking of references", I don't know :)

I figured out - partially how to solve the circular reference problem.

I just iterated over my queried collection (with Include() ) and set the backreferences to the parent to NULL. That worked for the serialisation issue which otherwise already breaks on the server.

The only problem now is the update of a data entity - its failing because the arrays of the referenced entitycollection are static...

Bart Jolling

To solve the cyclic backreference, you can use the IgnoreDataMember attribute. Or you can set the back reference to NULL before returning the data from the DbDataController

I posted a working solution to your problem in a different question, but using Entity Framework Code First. https://stackoverflow.com/a/10010695/1226140

Here I show how to generate your client-side model manually, allowing to you to map the data however you please

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!