0

I'm working with a nested list (List inside List) everything is working fine but when I try to get response from Api (GetOrders) it is not showing lists. I try to .include(x=>x.ShopOrdersList) but It is only including "ShopOrdersList" and the second list "OrderSummaries" which is inside "ShopOrdersList" is not showing. My model is follow

 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; }
}

and the controller code is

// GET: api/Orders
    public IQueryable<Orders> GetOrders()
    {
        return db.Orders.Include(x => x.ShopOrdersList);
    }

This is response that I'm getting. Response Now I want to include "OrderSummaries" list. Thanks in advance.

1 Answer 1

1

Check this answer EF LINQ include multiple and nested entities Its saying you can call ThenInclude to add nested entries

 public IQueryable<Orders> GetOrders()
    {
        return db.Orders.Include(x => x.ShopOrdersList).ThenInclude(y=>y.OrderSummaries);
    }
Sign up to request clarification or add additional context in comments.

4 Comments

There is not any "ThenInclude" extension method
Have you checked the link I mentioned?
Yes I have checked that link from that I get a clue to use "Select" extension method which works perfectly. Thanks for your response.
Cool, I am glad that helped :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.