Reputation: 4506
I was doing some messing around with dbcontext / EF and both produce the same thing for my needs. Are these actually equivalent? Any interesting points to consider on the difference?
//Something
var user = dbContext.Set<User>()
.Include(u => u.Preferences).FirstOrDefault(u => u.Id == userID);
//Something else
var user = dbContext.Set<User>().Where(u => u.Id == userID)
.Include(u => u.Preferences).FirstOrDefault();
..Just curious.
Thanks!
Upvotes: 0
Views: 58
Reputation: 6491
Like in @ThomasLevesque answer they're functionally equivalent.
More, EF translate them in the same expression tree (a where expression and a Join/UnionAll - in this case only a Join - expression to solve the Include).
So, a single EF provider returns always the same query.
Upvotes: 0
Reputation: 292355
They're functionally equivalent, and should result in the same SQL query being executed against the database (depending on how the Linq provider is implemented, of course).
Upvotes: 4