M
M
Michael2015-02-24 18:38:59
ASP.NET
Michael, 2015-02-24 18:38:59

How harmful are navigational properties (EF)?

Hello everyone, is it worth using navigation properties to add related data to the database, or can it be done in another way? I read that each call to the navigation property generates a new query to the database.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-02-25
@MickMS

Use it unequivocally, but prudently. Everything strongly depends on the task, but:
- if the related data is definitely needed, then it can be loaded with one request (see .Include(...));
- with lazy loading, the request will be _only_ when accessing the property, but if you do not use include, then this is a request anyway;
- probably we are talking about code first, do not forget about indexes (fluent api)
- if everything gets bad, you can always use views (including materialized ones) or direct queries

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question