This is a small, simple and very basic Tip. But for beginners like me can still make silly mistake while using these two gems during LINQ to SQL. The exceptions generated by these really frustrates beginners if they are not concerned about the results they expect from their queries.
Here is the basic difference that might help us during keying our queries.
|
SingleOrDefault |
FirstOrDefault |
|
This returns |
|
Here, when there is no |
|
It should be used when more |
Examples are the best way to express. Lets take one.
Suppose we have a Books table for querying, with BookId as PrimaryKey || BookName as Required and AuthorName as Nullable.

Join the conversation! Your thoughts help the community grow.