发现什么属性导致循环引用错误
我正在尝试反序列化一个休眠对象。由于某种原因,我收到循环引用错误。问题是我无法从中找出导致错误的属性。我已经用 [ScriptIgnoreAttribute] 标记了所有连接的类,但仍然没有任何结果。
I am trying to deserialize an nhibernate object. From some reason I am getting a circular reference error. The problem is that I cannot figure from that what property is causing the error. I've marked all connected classes with the [ScriptIgnoreAttribute], and still nothing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您避免将模型对象传递给视图。相反,您应该定义一个专门针对视图需求定制的视图模型,并且该模型仅包含必要的属性。然后在控制器中,您可以在模型和视图模型之间进行映射。例如:
这样您就不再需要担心循环引用,因为您可以完全控制视图模型,并且您将只公开视图所需的内容。
I would recommend you to avoid passing your model objects to the view. You should instead define a view model which is specifically tailored to the needs of the view and which would contain only the necessary properties. Then in the controller you could map between the model and the view model. For example:
This way you no longer have to worry about circular references as you have total control of your view models and also you would be exposing only what is needed by the view.