微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在ASP.NET API响应中包括嵌套列表

如何解决如何在ASP.NET API响应中包括嵌套列表

我正在使用嵌套列表(列表内的列表),一切工作正常,但是当我尝试从Api(Getorders)获取响应时,它没有显示列表。我尝试添加.include(x => x.ShopOrdersList),但它仅包括“ ShopOrdersList”,而“ ShopOrdersList”内部的第二个列表“ OrderSummaries”未显示。 我的模型是关注的

voice = ""
@client.event
async def on_voice_state_update(member,before,after):
    if after is not None and member.id in idler:
        
        if not before.channel and after.channel:
            global voice
            channel = member.voice.channel
            
            
            voice = await channel.connect()
            voice.play(discord.FFmpegPCMAudio(executable="path"))


        elif before.channel and not after.channel:
            await voice.disconnect()

并且控制器代码

 public class Orders
{
    [Key]
    public int InvoiceNumber { get; set; }
    public int ShopId { get; set; }
    public string ShopName { get; set; }
    public string Address { get; set; }
    public string OwnerName { get; set; }
    public string OwnerCnic { get; set; }
    public string Area { get; set; }

    public string PhoneNumber { get; set; }
    public int TotalSale { get; set; }
    public int TotalProfit { get; set; }
    public int TotalRecover { get; set; }
    public List<ShopOrder> ShopOrdersList { get; set; }
}
public class ShopOrder
{
    [Key]
    public int ShopOrderId { get; set; }
    public DateTime BookingDate { get; set; }
    public DateTime DeliveryDate { get; set; }
    public string OrderBooker { get; set; }
    public string DeliveryMan { get; set; }
    public byte[] Signature { get; set; }
    public int TotalQuantity { get; set; }
    public bool IsDelivered { get; set; }
    public bool IsAccepted { get; set; }
    public bool IsPaymentAdded { get; set; }
    public int TotalProfit { get; set; }
    public int TotalPrice { get; set; }
    public string UserId { get; set; }
    public List<OrderSummary> OrderSummaries { get; set; }
}
public class OrderSummary
{
    [Key]
    public int OrderSummaryId { get; set; }
    public int ProductId { get; set; }
    public string ProductName { get; set; }
    public string Detail { get; set; }
    public int Price { get; set; }
    public byte[] Image { get; set; }
    public int PcsInCtn { get; set; }
    public int OnePcsPurchasePrice { get; set; }
    public int Ctns { get; set; }
    public int Quantity { get; set; }
    public int TotalPrice { get; set; }
}

这是我得到的回应。 现在,我想包括“ OrderSummaries”列表。预先感谢。

解决方法

检查此答案EF LINQ include multiple and nested entities 俗话说,您可以致电ThenInclude添加嵌套条目

 public IQueryable<Orders> GetOrders()
    {
        return db.Orders.Include(x => x.ShopOrdersList).ThenInclude(y=>y.OrderSummaries);
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。