我试图在 Include(p => p.SubCategory) 之后获取 SubCategory 并收到错误:
“Newtonsoft.Json.JsonSerializationException:‘检测到类型‘E_Store2021.Models.Product’的自引用循环。路径‘[0].Product.SubCategory.Products’”
我需要获取 SubCategoryName。这种情况我该怎么办?没有 Include() 一切正常。公司也会发生同样的情况。
标记:
<tr>
<td>
<figure class="itemside align-items-center">
<div class="aside"><img src="@("~/images/content/" + item.Product.ImagePath)" asp-append-version="true" class="img-sm"/></div>
<figcaption class="info">
<a href="#" class="title text-dark" data-abc="true">@item.Product.ProductName</a>
<p class="text-muted small">Category: <br> Brand: @item?.Product?.Company.CompanyName</p>
<p class="text-muted small">SubCategory: @item.Product?.SubCategory?.SubCategoryName</p>
</figcaption>
</figure>
</td>
<td>
<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</td>
<td>
<div class="price-wrap"> <var class="price">@item.Product.UnitPrice</var> <small class="text-muted"> $9.20 each </small> </div>
</td>
<td class="text-right d-none d-md-block"> <a data-original-title="Save to Wishlist" title="" href="" class="btn btn-light" …Run Code Online (Sandbox Code Playgroud)