๐๐ฌ๐ ๐จ๐ ๐๐ฌ๐๐จ๐๐ซ๐๐๐ค๐ข๐ง๐ : For read only queries e.g. (GetAll,GetById etc.) use AsNoTracking , when we use it entities are not tracked for change so it brings data more speedily.
๐๐ง๐๐ฅ๐ฎ๐๐ ๐ง๐๐๐๐ฌ๐ฌ๐๐ซ๐ฒ ๐๐ง๐ญ๐ข๐ญ๐ข๐๐ฌ ๐๐ง๐ ๐๐จ๐ฅ๐ฎ๐ฆ๐ง๐ฌ : While retrieving data from multiple table make sure to include only necessary tables if you add tables that are not needed it will increase headache of query. Use eager loading only when it is necessary. Similarly donโt select the all columns from table , just retrieve necessary columns information using SELECT
๐ ๐จ๐ซ ๐ฅ๐๐ซ๐ ๐ ๐๐๐ญ๐ ๐ฎ๐ฌ๐ ๐๐ค๐ข๐ฉ ๐๐ง๐ ๐๐๐ค๐ : When you are dealing with a lot of information use skip and Take to retrieve data from table because if we try to bring all data in single try it can take time that will give bad user experience Skip & Take two integer and skips provided values and then takes next values.
๐๐ฌ๐ ๐๐ฌ๐ฒ๐ง๐ ๐ฆ๐๐ญ๐ก๐จ๐๐ฌ : For better user experience use async methods e.g. FirstOrDefaultAsync , SingleOrDefaultAsync and ToListAsync
๐๐๐๐ฎ๐๐ ๐๐ซ๐ข๐ฉ๐ฌ ๐ญ๐จ ๐๐๐ญ๐๐๐๐ฌ๐ : Use bulk operations available for SAVE/DELETE operations instead of iterating one by one it will reduce trips to database. After that only write one line await _context.SaveChangesAsync(); to reflect changes over database.
๐๐ฌ๐ ๐๐ซ๐ฒ๐๐๐ญ๐๐จ๐ง๐๐ง๐ฎ๐ฆ๐๐ซ๐๐ญ๐๐๐๐จ๐ฎ๐ง๐ญ : While working with large collection of data we use pagination and our pagination is displayed on the basis of total records available. So instead of .Count() method use TryGetNonEnumeratedCount it attempts to determine the number of elements in a sequence without forcing an enumeration.
๐๐ฌ๐ ๐จ๐ ๐๐๐ฎ๐๐ซ๐ฒ๐๐๐ฅ๐ : When you are dealing with a long list of filters and your filters are condition based make use of IQueryable ,it executes queries on the server side. After all conditions we can useย .ToList()ย to fetch data , so it makes query faster because we are first creating complete query and then we are bringing the data.

Leave a Reply