0

I have a question want to ask about AsNoTracking() method of EF I've write code:

await _context.Company.AsNoTracking().ToListAsync();

My purpose is want to this code will return an list, with AsNoTracking() is make EF doesn't track it, because list is read-only But, my Leader said remove "AsNoTracking()" because it is redundant. So, maybe i wrong understand, i hope you help me understand about it Thank

Johnathan Barclay
  • 18,599
  • 1
  • 22
  • 35
EddyLee
  • 803
  • 2
  • 8
  • 26
  • If you are not going to modify entities use `AsNoTracking()` to avoid tracking mechanism overhead. – Artur Sep 07 '21 at 08:29
  • Unless this is applied elsewhere, it is not redundant – TheGeneral Sep 07 '21 at 08:30
  • If you will never call `SaveChanges()`, using `AsNoTracking()` in query you will get better efficiency. refer to: [MSDN - Tracking vs. No-Tracking Queries](https://learn.microsoft.com/en-us/ef/core/querying/tracking) and [What difference does .AsNoTracking() make?](https://stackoverflow.com/a/22807021/15422161) – Hanabi Sep 07 '21 at 08:42

0 Answers0