Maverick
Maverick

Reputation: 37

Entity Framework Joining 3 Tables Together

var InventoryWares = SOM5Context.InventoryWares;
var InventoryDetails = SOM5Context.InventoryDetails;
var Items = SOM5Context.Items;

var goods = InventoryWares.Join(InventoryDetails,
                                p => p.PalletID,
                                x => x.PalletID,
                                (InventoryWare, InventoryDetail) => new { InventoryWare, InventoryDetail }).Join(Items.ToList(),
                                InventoryWare => InventoryWare.InventoryWare,
                                InventoryDetail => InventoryDetail.ItemNumber,
                                (WareItemNumber, ItemNumber) => new { WareItemNumber, ItemNumber })
                                .Select();

I'm getting an error when trying to join these three tables together, and been unable to solve the issue. The error I'm getting is:

The type arguments for method 'Queryable.Join(IQueryable, IEnumerable, Expression>, Expression>, Expression>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

The three vars, InventoryWares, InventoryDetails, and Items are the three tables I am trying to join together. The red squiggle is on my second join statement.

I thought adding the full parameter name would help explicitly state what I am looking to use, but that's not working.

Upvotes: 0

Views: 77

Answers (1)

Tiago Sousa
Tiago Sousa

Reputation: 963

This should work for you:

var goods = InventoryWares.Join(InventoryDetails,
        p => p.PalletID,
        x => x.PalletID,
        (InventoryWare, InventoryDetail) => new {InventoryWare, InventoryDetail})
    .Join(Items,
        x => x.InventoryWare.ItemNumber,
        Item => Item.ItemNumber,
        (x, Item) => new {x.InventoryWare, x.InventoryDetail, Item});

Goods will be a IQueryable where each item will have 3 properties: { InventoryWare, InventoryDetail, Item }

If this is not the query you were expecting, please provide more details on what you are trying to achieve.

Upvotes: 1

Related Questions