Sorry if this is too obvious, I was wondering is there a difference between the two blocks of code below in terms of performance and amount of data retrieved?
will specifying the id in the end of the query (like in FirstOrDefaultAsync(b => b.BuyModelId == modelId)
) brings all the table data first and then evaluate it against the id?
and will calling the Where
function in the beginning (like this Where(b => b.BuyModelId == modelId)
) will evaluate the data against the id and then call the include functions ?
So to summarize my question: is there a specific order to which those statements execute?
because I was worried that there might be some extra overhead in my calls to the database.
public async Task<BuyModel> GetModelById(int modelId)
{
return await _applicationDbContext.BuyModels
.Where(b => b.BuyModelId == modelId)
.Include(b => b.Buyer)
.Include(b => b.ItemsToBuy).ThenInclude(p => p.Category)
.Include(b => b.ItemsToBuy).ThenInclude(p => p.SalesUser).FirstOrDefaultAsync();
}
public async Task<BuyModel> GetModelById(int modelId)
{
return await _applicationDbContext.BuyModels
.Include(b => b.Buyer)
.Include(b => b.ItemsToBuy).ThenInclude(p => p.Category)
.Include(b => b.ItemsToBuy).ThenInclude(p => p.SalesUser).FirstOrDefaultAsync(b => b.BuyModelId == modelId);
}