The difference between First() and FirstOrDefault() is a major concept in Entity Framework.
Let's try both with an example.
The major difference between First and FirstOrDefault is that First() will throw an exception if there is no result data for the supplied criteria whereas FirstOrDefault() will return the default value (null) if there is no result data.
First() will throw an exception if there is no result data, as you can see below.

FirstOrDefault() returns the default value (null) if there is no result data and you can see the result in the following screen.


Pravin LalgePosted Oct 15, 2018, 12:32 AM
Yes I have done with EF
Pravin LalgePosted Oct 15, 2018, 12:29 AM
OK THANKS FOR FEEDBACK :)
Mahesh ChandPosted Oct 14, 2018, 8:24 PM
Reference: Https://www.c-sharpcorner.com/blogs/difference-between-first-and-firstordefault-in-linq1
Mahesh ChandPosted Oct 14, 2018, 8:24 PM
Here is a reference
Mahesh ChandPosted Oct 14, 2018, 8:23 PM
You may want to correct the EF part. First() and FirstOrDefault() are actually LINQ syntax and you're using LINQ on a List<T>. Cheers!