Reputation: 5478
Is there any performance difference between the following two queries?
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();
Perhaps there's another, even faster one?
Upvotes: 0
Views: 344
Reputation: 865
In terms of compilation, they should be compiled into the the same code; Linq is just syntactic sugar which the compiler will interpret for you. That being said, not all linq queries will be compiled in the way you expect and regardless you should always check the generated sql using the ObjectQuery
cast + ToTraceString
method.
Upvotes: 1