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.
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.
ObjectQuery.ToTraceString