EF Core Left Join and then Inner Join

c# entity-framework-core sql-server

Question

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.

1
1
7/17/2017 10:17:38 AM

Accepted Answer

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();
2
11/30/2017 1:57:22 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow