.Where(< condition>).FirstOrDefault()与.FirstOrDefault(< condition>) [英] .Where(<condition>).FirstOrDefault() vs .FirstOrDefault(<condition>)
本文介绍了.Where(< condition>).FirstOrDefault()与.FirstOrDefault(< condition>)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Linq to Entities在以下内容之间有区别吗?
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 simply a matter of personal preference?
谢谢.
推荐答案
两者均生成相同的SQL语句.第二种方法更短一些,而第一种方法对于某些开发人员可能更清晰.最终,这是个人喜好问题.
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.
这篇关于.Where(< condition>).FirstOrDefault()与.FirstOrDefault(< condition>)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文