且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#MVC4 Web API-结果JSON应该返回对象而不是$ ref到对象

更新时间:2023-11-27 19:24:16

一种简单的方法是编辑生成的实体类代码.对于每个实体类,将分配一个[DataContract(IsReference=true)]属性.

An easy way is to edit the generated entity classes code. For each of the entity classes, there will be a [DataContract(IsReference=true)] attribute assigned.

类似以下内容:

[EdmEntityTypeAttribute(NamespaceName="YourNamespace", Name="YourEntity")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class YourEntity : EntityObject
{

将其更改为IsReference=false.那应该可以解决问题.

Change it to IsReference=false. That should do the trick.