Entity Framework Navigation Properties looping issue though WCF

半世苍凉 提交于 2019-12-05 08:50:35

There are two issues if you try to use WCF:

  • First issue: Do you want to return related entities as well? Always turn off lazy loading when working with WCF / serialization and make sure that you manually use Include for relations you really want to return. Otherwise lazy loading will load all relation in the object graph. Moreover depending on the way how your service handles context's life cycle, the lazy loading can happen when the context is already disposed.
  • You must tell serializer about the circular reference or remove the circular reference. WCF by default uses DataContractSerializer. To remove the circular reference you can mark one of those navigation properties with IgnoreDataMember attribute or you can simply tell serializer about the circular reference by marking all entities with DataContract(IsReference = true) attribute and all member properties which should be serialized with DataMember attribute.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!