FirstOrDefaultAsync() & SingleOrDefaultAsync() vs FindAsync() EFCore

FindAsync

In much of the scaffolded code, FindAsync can be used in place of
FirstOrDefaultAsync.

SingleOrDefaultAsync

fetches more data and does unnecessary work. throws an exception if
there’s more than one entity that fits the filter part.

FirstOrDefaultAsync

doesn’t throw if there’s more than one entity that fits the filter
part.

https://learn.microsoft.com/en-us/aspnet/core/data/ef-rp/crud?view=aspnetcore-2.2#singleordefaultasync-vs-firstordefaultasync

Leave a Comment