G
G
Gennady Kruglov2022-04-12 22:37:57
C++ / C#
Gennady Kruglov, 2022-04-12 22:37:57

What is the best way to retrieve data from a database?

What is more optimal in terms of the complexity of the query to the database, the speed of its execution and the memory occupied after the query is completed?

Such a request:

var itemName = dbcontext.Items.Where(i => i.id == 1).Select(i => i.Name).FirstOrDefault();


Or like this:
var itemName = dbcontext.Items.FirstOrDefault(i => i.id == 1)?.Name;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2022-04-13
@HemulGM

It is desirable to find out what kind of query is formed in the database. You will find out which one is being formed - you will see which one will be more optimal.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question