EF lazy loading LazyLoad

Lazy loading only useful for related attributes (Navigation Property), common property is no such thing.

Lazy loading is a one of the read attribute, called once, read once.

condition:

context.Configuration.ProxyCreationEnabled = true;(默认为true)

context.Configuration.LazyLoadingEnabled = true;(默认为true)

POCO classes for the public, navigation attributes to add virtual modifier.

NOTE: POCO --- Plain Old CLR Object, those that do not include the original class INSERT, DEL and other data persistence and any business logic operations.

Principle Analysis:

EF subclass generate dynamic entity class, and then override the virtual attribute (if it is not added virtual property value can not be obtained)

Advantages: Avoid disposable loading all data, increasing the speed of loading.

Disadvantages: with loaded once again, increase the pressure on the database server.

So, when more data in the database, the more we came to use the data, it is recommended to use lazy loading, whereas the use of pre-loaded.

Guess you like

Origin www.cnblogs.com/1016391912pm/p/12037869.html