What is a difference between dbContext.Orders.First() and dbContext.Orders.Single() in Entity Framework?

Experience Level: Medior
Tags: Entity Framework

Answer

The difference is that dbContext.Orders.Single() will throw an exception if there is no element in the collection, while dbContext.Orders.First() returns null.

Comments

No Comments Yet.
Be the first to tell us what you think.
Entity Framework Core
Entity Framework Core

Are you learning Entity Framework ? Try our test we designed to help you progress faster.

Test yourself