Json.Net adding $id to EF objects despite setting PreserveReferencesHandling to “None”

后端 未结 1 1905
时光取名叫无心
时光取名叫无心 2020-11-30 12:57

I\'ve already looked at how to remove $id during JSON serialization but the answers given do not seem to be working for me and I hope someone can figure out what I am doing

相关标签:
1条回答
  • 2020-11-30 13:18

    The custom ContractResolver setting overrides the PreserveReferencesHandling setting.

    In your implementation of DefaultContractResolver/IContractResolver, add this;

    public override JsonContract ResolveContract(Type type) {
        var contract = base.ResolveContract(type);
        contract.IsReference = false;
        return contract;
    }
    

    This behaves similarly to the PreserveReferencesHandling.None setting without a custom ContractResolver.

    0 讨论(0)
提交回复
热议问题