4
\$\begingroup\$

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();
asked Jul 26, 2011 at 15:40
\$\endgroup\$

1 Answer 1

6
\$\begingroup\$

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.

answered Jul 26, 2011 at 15:53
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I agree, I think it is better to use consistent syntax. I prefer expression syntax for joins too. \$\endgroup\$ Commented Jul 26, 2011 at 16:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.