Which syntax results in better performance?
var vRec = (bNoTracking ? tblOrders.AsNoTracking() : tblOrders);
return vRec
.Where(x => (x.WarehouseId == iWarehouseId) && (x.OrderId == iOrderId))
.FirstOrDefault<tblOrder>();
var vRec = (bNoTracking ? tblOrders.AsNoTracking() : tblOrders);
return (from rec in vRec
where (rec.WarehouseId == iWarehouseId) && (rec.OrderId == iOrderId)
select rec)
.FirstOrDefault<tblOrder>();
Both queries will be converted to the same SQL, meaning performance will be identical. It just depends on if you prefer the "fluent" syntax (.Where()
) or LINQ query expressions (where
).
The SQL generated from my test MSSQL database is as follows, revealed with LINQPad:
This looks to be about as optimized as it'll get, so I'd say no further tweaking is necessary unless you're running this select in some kind of loop.