Kyle
Kyle

Reputation: 33739

When I get a value through a navigation property does entityframework run an sql query or does it already have the data?

Lets say there is a User entity, and there is a Group entity, User has a GroupId to relate it to a group, and there is a Group navigation property on the User entity.

I have retrieved 1 User through EF. when I do user.Group.Name does EF run a sql query to join it with group to get the name of the group, or did it get that data when I got the user object?

Upvotes: 0

Views: 967

Answers (1)

StackTrace
StackTrace

Reputation: 9416

Entity Framework supports three ways to load related data.

  • Eager Loading
  • Lazy Loading
  • Explicit Loading

A quick read of the following blog could be of help http://blogs.msdn.com/b/adonet/archive/2011/01/31/using-dbcontext-in-ef-feature-ctp5-part-6-loading-related-entities.aspx

Upvotes: 1

Related Questions