Accepted answer

you probably need to enable eager loading for the "owneditems" navigation property in the query:

please post your full linq query if i should give an example.

update 1

seems like subqueries have n+1 problems in ef core and it will maybe be fixed in version 3.


update 2

if you don't need to fully materialize "items" you should be able to do something like this where you create an anoymous object instead which should "trick" ef into what you want:

from item in items
select new
   owned = owneditems.any(own => own.userid == userid && own.itemid ==,
   item = new { id =, name = }



you need to tell ef to load the related data, in this case the owneditems table.

one way to go about this is to include the related table. if there's a foreign key that links tables it could be easily done like this:

var datawithrelateddata = db_context.items.include(x => x.owneditems).select ...

another way to avoid a high number of round trips to the database is to load both datasets in separate queries and then merge them in memory. so you would first make a query to items then with the data returned another query to owneditems and lastly merge them into a single list of objects. this would do just 2 calls to the database, therefore improving performance.

Related Query

More Query from same tag