N
N
NovikovNik2019-11-19 01:42:23
.NET
NovikovNik, 2019-11-19 01:42:23

Which data loading approach in Entity Framework 6 to choose?

Tell me please.
There are three ways to load data in EF 6: greedy, explicit, lazy.
It is also possible to send SQL queries directly to the database through the Database property.
It's closer and easier for me to send SQL queries. However, I'm a bit confused and can't figure out the following: do I have to use one of the three ways to load data, or can I use them if I'm not comfortable doing SQL queries?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2019-11-19
@sarapinit

These are not mutually exclusive things. Lazy loading is performed when a property is accessed, if the property has not yet been loaded (it must be enabled in the settings). You can combine these approaches by preloading properties using either eager loading or explicit loading for specific queries. If the property has already been loaded, then there is no need for lazy loading to work. The main thing is to understand how queries occur in the database with different types of loading.

V
Vladimir Korotenko, 2019-11-25
@firedragon

Use the built-in functionality of the server. For MS SQL, this is bulkinsert. For other bases there are analogues.
EF adds too many checks, for a single record this is acceptable, but too much time is lost with a batch insert.
See the difference when using different approaches
https://github.com/vkorotenko/OrmTestSpeed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question