Is there any different in performance for the following 2 queries. I'm just wondering what is the better of the two:
var res1 = (from a in _ctx.DataContext.Actions
join e in _ctx.DataContext.Events on a.EventId equals e.EventId
select a).Single(a => a.ActionId == actionId);
or
var res2 = (from a in _ctx.DataContext.Actions
join e in _ctx.DataContext.Events on a.EventId equals e.EventId
where a.ActionId == actionId
select a).Single();
1 Answer 1
There should not be any performance difference that is a result of the syntax used. The query syntax is just eye candy that gets converted to the same underlying code. The difference between the two is really just
_ctx.DataContext.Actions
.Join(_ctx.DataContext.Events, blah, blah, blah)
.Single(a=>a.ActionId == actionId);
vs.
_ctx.DataContext.Actions
.Join(_ctx.DataContext.Events, blah, blah, blah)
.Where(a=>a.ActionId == actionId)
.Single();
If there's a performance difference, I'd be very surprised. The only way to really tell is to run some tests. I personally prefer your second method or my first; as I do not like mixing query syntax with imperative syntax.
-
1\$\begingroup\$ I agree, I think it is better to use consistent syntax. I prefer expression syntax for joins too. \$\endgroup\$jaffa– jaffa2011年07月26日 16:02:59 +00:00Commented Jul 26, 2011 at 16:02