Question

I have an entity set that is a Session for a survey. There is a navigation property to a collection of Responses that are also keyed to an Question entity (using a foreign key relationship in the DB).

It is easy for me to call up the collection of responses by simply doing

session.Responses

That returns an enumerated list, which for most cases is fine.

However, for large datasets I'm running into a conceptual problem.

If I want to select a particular response from a Session's Response collection based on an Item, given that it is a collection would it be a seek or a scan operation? Does the FK relationship between Response and Question get utilized at all?

If not, would it be wise to create a Keyed Dictionary in a Session Partial class that takes it's Response collection and pairs it with Question Keys? That way, it would be a direct seek to yield the exact Response per requested Question.

Était-ce utile?

La solution

LINQ over objects uses Enumerators, which "scan" over the collection.

EDIT: Your best bet is to do as much logical joining and filtering in the database as possible. When you load a Dictionary with the results of an EF query expression, the query will be executed on the database and the results placed into memory. At this moment you are no longer dealing with an IQueryable expression, but an IEnumerable set of objects. Further LINQ expressions on the Dictionary are LINQ over objects.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top