Do you only explicitly include relationships you need?

Last updated by Brook Jeynes [SSW] 10 months ago.See history

Often developers will include all the related entities in a query to help with debugging. Always remember to take these out. They cause excessive database load.

If you need the related entities, then that is what Include is for.

var query = _dbContext
        .Include(x => x.SalesPerson);

Figure: Bad example - Retrieved the sales records and the salesperson, even though we don't intend to use the salesperson record.

var query = _dbContext

Figure: Good example - Retrieved only the sales records themselves

We open source. Powered by GitHub