1

I have 3 related Tables in MS SQL Server.

Database Schema

Table_Bid and Table_Stock are related to Table_Product with ProductId.

I want to fetch the Data like this query in Entity Framework Core

Select * from Table_Bid
left join Table_Product on Table_Bid.ProductId = Table_Product.Id
inner join Table_Stock on Table_Stock.ProductId =  Table_Bid.ProductId

Using .Include and .ThenInclude i am unable to fetch the records, rather while using this query i am getting the records

My C# Code is :

        List<TableBid> bid =
            _context.TableBid
            .Include(c => c.Product.TableStock)
            .ToList();

Please guide me how to get data from all three table at once using Entity Framework Core.

Mohammed Altaf
  • 97
  • 1
  • 1
  • 11
  • Does https://stackoverflow.com/a/39268390/34092 help? – mjwills Jul 17 '17 at 11:03
  • Could you specify more clearly what is your specific problem here? Is it that you dont get any result, or are you getting results but the navigation properties are null or empty lists where they shouldnt? – Daniel García Rubio Jul 17 '17 at 11:41

1 Answers1

2

As @Daniel García Rubio noted, it is hard to answer your question with the small amount of information you provided in your question. Without knowing more though, it would seem like you are looking for the following:

List<TableBid> bid =
        _context.TableBid
        .Include(bid => bic.Product.TableStock)
        .ThenInclude(stock => stock.Product)
        .ToList();
peinearydevelopment
  • 11,042
  • 5
  • 48
  • 76