Does anyone have a simple code example in linq2sql that demonstrates the difference between Eager Loading and Lazy Loading?
Does anyone have a simple code example in linq2sql that demonstrates the difference between
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Deferred Loading: for a given entity, it’s associated collections may be empty when it is first loaded, but when these collections are first iterated, LINQ to SQL fires off a query to load these collections after it is loaded the collection is then available for future use without requiring another query:
The
OrderDetailsare loaded only if it is iterated, so If theOrderDetatilsare never iterated the corresponding query is never executed.Eager Loading: immediate loading the associated Collections for all referenced entities for example LINQ to SQL will automatically brings all the
OrderDetailsfor all the retreived Ordersnote that: Deferred execution is a LINQ Feature but Deferred Loading is a LINQ to SQL feature