Reputation: 1898
Which syntax results in better performance?
var vRec = (bNoTracking ? tblOrders.AsNoTracking() : tblOrders);
return vRec
.Where(x => (x.WarehouseId == iWarehouseId) && (x.OrderId == iOrderId))
.FirstOrDefault<tblOrder>();
OR
var vRec = (bNoTracking ? tblOrders.AsNoTracking() : tblOrders);
return (from rec in vRec
where (rec.WarehouseId == iWarehouseId) && (rec.OrderId == iOrderId)
select rec)
.FirstOrDefault<tblOrder>();
This question is for EF-6 (for SQL Express 2014) and EF-7 version 7.0.0-rc1-final (for SQLite).
Note: I'm not looking for opinions on coding style difference, only whether there is technical reason to prefer one another.
Upvotes: 0
Views: 750
Reputation: 5369
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.
Upvotes: 3