Search code examples
c#entity-framework-4

EF Query with multiple contexts


I have two EF contexts _inventoryContext and _auctionContext.

_inventoryContext has a property called Items and _auctionContext has one called Auctions. Items is a collection of Item objects which each contain a Guid to identify them uniquely. The Auctions property is a collection of Auction objects which each contain a Guid InventoryReference that refers to one of the elements of Items.

What I want to do is get a list of all inventory items that are not part of an auction. How do I do this?


Solution

  • This may be of help to you.

    Alternatively, you can do this in 2 steps: First get a collection of GuidReferences from your Auction, and then fetch the Items whose Guid's are included in the collection. There will be a performance hit because of the extra query, and because the framework will need to allocate the Guid collection. But depending on the Item collection size, that may not be a big deal for you.

    Another possibility would be to create a view in one database/context that pulls the data from the other. This would be read-only, however.