In my DB I have "Place" and "Image" table. "Image" has a foreign key from Place which means each place can have multiple images.
I select places like this:
var query = (from x in DB.Places
where x.CityId == CityId
The ObjectContext instance has been disposed and can no longer be used
for operations that require a connection.
You can use eager loading:
var query = (from x in DB.Places where x.CityId == CityId select x).Include(p => p.Images).ToList();
Method syntax looks better in that case
var query = DB.Places.Where(p => p.CityId == CityId).Include(p => p.Images).ToList();
Another option - do not dispose DbContext until you get images. E.g. if you are using
using statement, just remove it or get images while you are inside
using block. But it will use second database query for loading images.