OData / AspNetCoreOData

ASP.NET Core OData: A server library built upon ODataLib and ASP.NET Core
Other
457 stars 158 forks source link

Does it make sense to call .AsNoTracking for OData GET controller actions? #968

Open VadimOvchinnikov opened 1 year ago

VadimOvchinnikov commented 1 year ago

There is .AsNoTracking() method in EF Core which ensures minimal memory usage and optimal performance for read operation. When I found examples of OData controllers online, I've never seen using .AsNoTracking() for Get and Get(id) methods. For example, in MS docs both

don't use it.

So, does it make sense to use it for OData read queries?

julealgon commented 1 year ago

Yes it does. Using AsNoTracking on basically every "read-only" interaction with the context is probably a good idea.

The reason this is not mentioned in OData documentation is probably because it really is not an OData-specific concern, I'd imagine. Usually you want the documentation for your product/library to focus on concerns only for your library and leave as much of external things out.

Also, at the end of the day, we are talking about an optimization here. Usually samples don't include them, as well.

Maybe the full actual project samples should consider using it though.

corranrogue9 commented 1 year ago

Thanks @julealgon, we will try this out in one of our samples, and we agreed that we should update the docs to use this since it would be best practice in those cases.