[英]Linq to SQL fastest way to retrieve a single record
以下兩個查詢之間是否有性能差異?
CustomerProduct customerProduct = db.CustomerProducts.SingleOrDefault(p => object.Equals(p.Customer, this));
CustomerProduct customerProduct = (from p in db.CustomerProducts where object.Equals(p.Customer, this) select p).SingleOrDefault();
也許還有另一個甚至更快的?
在編譯方面,應將它們編譯為相同的代碼。 Linq只是編譯器將為您解釋的語法糖。 話雖如此,並不是所有的linq查詢都將按照您期望的方式進行編譯,並且無論您何時應始終使用ObjectQuery
cast + ToTraceString
方法檢查生成的sql。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.