<legend id='uyaym'><style id='uyaym'><dir id='uyaym'><q id='uyaym'></q></dir></style></legend>
    • <bdo id='uyaym'></bdo><ul id='uyaym'></ul>
  1. <small id='uyaym'></small><noframes id='uyaym'>

    <tfoot id='uyaym'></tfoot>

      <i id='uyaym'><tr id='uyaym'><dt id='uyaym'><q id='uyaym'><span id='uyaym'><b id='uyaym'><form id='uyaym'><ins id='uyaym'></ins><ul id='uyaym'></ul><sub id='uyaym'></sub></form><legend id='uyaym'></legend><bdo id='uyaym'><pre id='uyaym'><center id='uyaym'></center></pre></bdo></b><th id='uyaym'></th></span></q></dt></tr></i><div id='uyaym'><tfoot id='uyaym'></tfoot><dl id='uyaym'><fieldset id='uyaym'></fieldset></dl></div>
    1. 尽管将 PreserveReferencesHandling 设置为“None",但

      时间:2023-08-22

            <legend id='JhJh4'><style id='JhJh4'><dir id='JhJh4'><q id='JhJh4'></q></dir></style></legend>
            <tfoot id='JhJh4'></tfoot>
            <i id='JhJh4'><tr id='JhJh4'><dt id='JhJh4'><q id='JhJh4'><span id='JhJh4'><b id='JhJh4'><form id='JhJh4'><ins id='JhJh4'></ins><ul id='JhJh4'></ul><sub id='JhJh4'></sub></form><legend id='JhJh4'></legend><bdo id='JhJh4'><pre id='JhJh4'><center id='JhJh4'></center></pre></bdo></b><th id='JhJh4'></th></span></q></dt></tr></i><div id='JhJh4'><tfoot id='JhJh4'></tfoot><dl id='JhJh4'><fieldset id='JhJh4'></fieldset></dl></div>
              • <bdo id='JhJh4'></bdo><ul id='JhJh4'></ul>
                  <tbody id='JhJh4'></tbody>

                <small id='JhJh4'></small><noframes id='JhJh4'>

              • 本文介绍了尽管将 PreserveReferencesHandling 设置为“None",但 Json.Net 仍将 $id 添加到 EF 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我已经看过 如何在 JSON 序列化期间删除 $id 但给出的答案似乎对我不起作用,我希望有人能找出我做错了什么.

                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 wrong.

                这是我的代码:

                return JsonConvert.SerializeObject(target, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Include,
                    PreserveReferencesHandling = PreserveReferencesHandling.None,
                    ContractResolver = new CustomContractResolver(),
                    Converters = CustomConverters
                });
                

                这个输出仍然带有 $id's,但是,仅在实体框架对象上,这是设计使然吗?如果是这样,有什么方法可以防止实体框架对象上的那些 $id ?

                The output from this is still coming out with $id's, BUT, only on Entity Framework objects, is this by design? If so, is there any way to prevent those $id's on Entity Framework objects?

                推荐答案

                自定义 ContractResolver 设置会覆盖 PreserveReferencesHandling 设置.

                The custom ContractResolver setting overrides the PreserveReferencesHandling setting.

                DefaultContractResolver/IContractResolver 的实现中,添加这个;

                In your implementation of DefaultContractResolver/IContractResolver, add this;

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

                这与没有自定义 ContractResolverPreserveReferencesHandling.None 设置类似.

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

                这篇关于尽管将 PreserveReferencesHandling 设置为“None",但 Json.Net 仍将 $id 添加到 EF 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在生成的 JSON 中省略/忽略/跳过空对象文字 下一篇:反序列化具有以数字开头的某些属性名称的 jso

                相关文章

                最新文章

              • <small id='SQ4aU'></small><noframes id='SQ4aU'>

                  <i id='SQ4aU'><tr id='SQ4aU'><dt id='SQ4aU'><q id='SQ4aU'><span id='SQ4aU'><b id='SQ4aU'><form id='SQ4aU'><ins id='SQ4aU'></ins><ul id='SQ4aU'></ul><sub id='SQ4aU'></sub></form><legend id='SQ4aU'></legend><bdo id='SQ4aU'><pre id='SQ4aU'><center id='SQ4aU'></center></pre></bdo></b><th id='SQ4aU'></th></span></q></dt></tr></i><div id='SQ4aU'><tfoot id='SQ4aU'></tfoot><dl id='SQ4aU'><fieldset id='SQ4aU'></fieldset></dl></div>
                  <legend id='SQ4aU'><style id='SQ4aU'><dir id='SQ4aU'><q id='SQ4aU'></q></dir></style></legend>

                    <tfoot id='SQ4aU'></tfoot>
                    • <bdo id='SQ4aU'></bdo><ul id='SQ4aU'></ul>