9

I've been reading Entity Framework and people were crying over why there was not implicit lazy loading or something. Basically I've been searching things about Lazy Loading and now I know what it is : It is a design pattern which allows us to load objects when they are really needed.

But what is the difference between Explicit Lazy Loading and Implicit Lazy Loading.

Thanks in advance...

2 Answers 2

5

If you e.g. have an entity "OrderRow" and another entity "Order", there will be a navigational property on the OrderRow that points to the Order it belongs to.

Currently Entity Framework supports only Explicit Lazy Load which means that if you have retreived a number of OrderRows and want to check something on the Order you need to:

// or is an OrderRow
if(!or.Order.IsLoaded)
    or.Order.Load()

or.Order.Cancel();

However if you have implicit lazy loading you don't need the IsLoaded check, it will be done automatically, you can do or.Order.Cancel() directly and the Order will be loaded automatically if needed. This is how linq-to-sql works and it saves some typing and some risk for mistakes. On the other hand it makes it less clear exactly when and how database access will be performed. With implicit load it is easy to write inefficient code that makes one DB roundtrip for each line to be fetched from a table.

Sign up to request clarification or add additional context in comments.

3 Comments

So you mean explicit lazy loading is required for related tables?
No, Implicit loading means that the related tables are automatically loaded in the background.
.. more like in the foreground. The execution will block until it is fetched.
4

Explicit means you explicitly wrote your code to lazy load.

Implicit means that the framework (in this case EF) does lazy loading itself, whether you intended to or not.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.