<i id='BcQOn'><tr id='BcQOn'><dt id='BcQOn'><q id='BcQOn'><span id='BcQOn'><b id='BcQOn'><form id='BcQOn'><ins id='BcQOn'></ins><ul id='BcQOn'></ul><sub id='BcQOn'></sub></form><legend id='BcQOn'></legend><bdo id='BcQOn'><pre id='BcQOn'><center id='BcQOn'></center></pre></bdo></b><th id='BcQOn'></th></span></q></dt></tr></i><div id='BcQOn'><tfoot id='BcQOn'></tfoot><dl id='BcQOn'><fieldset id='BcQOn'></fieldset></dl></div>
      <bdo id='BcQOn'></bdo><ul id='BcQOn'></ul>
    <tfoot id='BcQOn'></tfoot>
  • <small id='BcQOn'></small><noframes id='BcQOn'>

    1. <legend id='BcQOn'><style id='BcQOn'><dir id='BcQOn'><q id='BcQOn'></q></dir></style></legend>
      1. 使用 Angular 2 在 Asp.net MVC 中检测到自引用循环

        时间:2023-06-06
      2. <tfoot id='zyoP1'></tfoot>
        <i id='zyoP1'><tr id='zyoP1'><dt id='zyoP1'><q id='zyoP1'><span id='zyoP1'><b id='zyoP1'><form id='zyoP1'><ins id='zyoP1'></ins><ul id='zyoP1'></ul><sub id='zyoP1'></sub></form><legend id='zyoP1'></legend><bdo id='zyoP1'><pre id='zyoP1'><center id='zyoP1'></center></pre></bdo></b><th id='zyoP1'></th></span></q></dt></tr></i><div id='zyoP1'><tfoot id='zyoP1'></tfoot><dl id='zyoP1'><fieldset id='zyoP1'></fieldset></dl></div>

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

              <bdo id='zyoP1'></bdo><ul id='zyoP1'></ul>
              <legend id='zyoP1'><style id='zyoP1'><dir id='zyoP1'><q id='zyoP1'></q></dir></style></legend>

                <tbody id='zyoP1'></tbody>

                • 本文介绍了使用 Angular 2 在 Asp.net MVC 中检测到自引用循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  1. 我创建了一个数据库,因为我有多个表之间存在关系.
                  2. 尝试从我的 WEB 应用程序获取数据时出现此错误<块引用>

                    "'检测到类型为 'System.Data.Entity.DynamicProxies.PrescriptionMaster_2C4C63F6E22DFF8E29DCAC8D06EBAE038831B58747056064834E80E41B5C4E4A'的自引用循环.PathMaster'[pPrescription]

                  3. 我不明白为什么我会收到这个错误,当我删除表之间的关系时,我从中获得了正确的数据.
                  4. 我尝试了其他解决方案,例如添加

                    "config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling= Newtonsoft.Json.ReferenceLoopHandling.Ignore;"

                    在 Webconfig.cs 中,但对我没有任何作用.

                  请帮帮我,我该怎么办?

                  解决方案

                  防止这种情况发生的唯一正确方法是不发送实体框架对象(可能包含此类循环)进入 JSON 序列化器(不太擅长知道何时停止序列化).

                  相反,创建模拟前端实际需要的 EF 对象部分的 ViewModel,然后使用 EF 对象填充这些 ViewModel.

                  一种快速而肮脏的方法是只使用匿名对象,例如:

                  返回新的{产品 = 新{Id = EF_Product.Id,名称 = EF_Product.Name}};

                  一个好的经验法则是仅将 EF 对象中的简单属性(数字、布尔值、字符串、日期时间)分配给 ViewModel 项.一旦遇到作为另一个 EF 对象(或 EF 对象的集合)的 EF 对象属性,那么您也需要将它们转换为未链接到 EF 的简单"对象.

                  另一方面,还有诸如 AutoMapper 之类的库.如果您决定需要实际的 ViewModel 类,那么 AutoMapper 将帮助以非常结构化的方式将 EF 对象映射到这些 ViewModel.

                  1. I Have Create a DB in that I am Having Multiple tables having Relationship between them.
                  2. When a try to get data from my WEb app i get this error

                    "'Self referencing loop detected with type 'System.Data.Entity.DynamicProxies.PrescriptionMaster_2C4C63F6E22DFF8E29DCAC8D06EBAE038831B58747056064834E80E41B5C4E4A'. Path '[0].Patient.PrescriptionMasters"

                  3. I coudn't get why i am getting this error, and when i remove the relationships between tables i get proper data From it.
                  4. I have Tried other solutions like adding

                    "config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; "

                    in Webconfig.cs but nothing has worked for me.

                  Please help me, what should I do ?

                  解决方案

                  The only proper way to prevent this from happening is by not sending Entity Framework objects (which may contain such loops) into the JSON Serializer (which is not too good at knowing when to stop serializing).

                  Instead, create ViewModels that mimic the parts of the EF Objects that your Front End actually needs, then fill those ViewModels using the EF Objects.

                  A quick-and-dirty way is to just use anonymous objects, for example:

                  return new
                  {
                      Product = new
                      {
                          Id = EF_Product.Id,
                          Name = EF_Product.Name
                      }
                  };
                  

                  A good rule-of-thumb is to only assign simple properties (number, bool, string, datetime) from the EF Objects to the ViewModel items. As soon as you encounter an EF Object property that is yet another EF Object (or a collection of EF Objects), then you need to translate those as well to 'simple' objects that are not linked to EF.

                  On the other end of the spectrum there are libraries such as AutoMapper. If you decide that you need actual ViewModel classes, then AutoMapper will help mapping the EF Objects to those ViewModels in a very structured way.

                  这篇关于使用 Angular 2 在 Asp.net MVC 中检测到自引用循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:我们可以在 PWA 应用程序中使用 SQLite 数据库吗 下一篇:无法格式化默认的 MySQL 日期时间

                  相关文章

                  最新文章

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

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

                    1. <legend id='kvWV8'><style id='kvWV8'><dir id='kvWV8'><q id='kvWV8'></q></dir></style></legend>
                      <tfoot id='kvWV8'></tfoot>