In this article let us look at the Single, SingleOrDefault, First, FirstOrDefault methods in Entity Framework. These methods return a single record from the database based on a Where condition. We use these methods when the Where condition is not part of the Primary Key, But we want only one record in the query result. If the Where condition is part of the primary key then use the find method.
LINQ to Entities
Database Queries in Entity Framework are written using LINQ to Entities. In this tutorial, we will learn how to use the Select clause to select all the rows. Learn to use the ToList method. Use the foreach loop to loop through the rows. How to filter using the Where clause. Sort the results on single or multiple fields using the OrderBy, orderByDescending, ThenBy & ThenByDescending clause. Also we will show you how to write EF Query using both the Method & Query Syntax
LINQ to Entities Tutorial in simple and easy steps. Learn to Query, Add, update.delete records from the database using LINQ to entities in entity framwork