.Where().FirstOrDefault() vs .FirstOrDefault()

前端 未结 1 939
自闭症患者
自闭症患者 2020-12-19 11:20

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

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

db.EntityName.FirstOrDefault(a         


        
相关标签:
1条回答
  • 2020-12-19 11:57

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

    You can inspect the SQL using the ObjectQuery.ToTraceString method.

    0 讨论(0)
提交回复
热议问题