.Where (<condition>). FirstOrDefault () vs .FirstOrDefault (<condition>)

Using Linq to Entities, is there a difference between the following?

 db.EntityName.Where(a => a.Id == id).FirstOrDefault(); db.EntityName.FirstOrDefault(a => a.Id == id); 

Or is it just a matter of personal preference?

Thanks.

+3
source share
1 answer

Both generate the same SQL statement. The second approach is shorter, while the first may be clearer for some developers. Ultimately, it is a matter of personal preference.

You can test SQL using the ObjectQuery.ToTraceString method.

+5
source

All Articles