SingleOrDefault
The LINQ operator that returns the only matching item or null, and throws if more than one item matches.
In more detail
It suits lookups by a unique key such as an identifier. The Async versions run the query against the database in EF Core.
Related terms
- FirstOrDefault — The LINQ operator that returns the first matching item, or null (or zero for value types) when nothing matches.
- LINQ — Language Integrated Query: a set of C# operators such as Where, Select and OrderBy for filtering, shaping and combining sequences of data.
- Entity Framework Core — Microsoft's object-relational mapper for .NET, which lets code query and save database data as C# objects and translates LINQ into SQL.
Taught in
- Querying, Change Tracking, and Saving Data — Modern .NET Core, C# & Enterprise Microservices