Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7978091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:23:48+00:00 2026-06-04T09:23:48+00:00

I’m perplexed by the below. I’ve been using LINQ in my projects using formats

  • 0

I’m perplexed by the below.

I’ve been using LINQ in my projects using formats such as:

var query =     
    from obj_i in set1
    join obj_j in set2 on 
        new { 
          JoinField1 = obj_i.SomeField1,
          JoinField2 = obj_i.SomeField2,
          JoinField3 = obj_i.SomeField3,
          JoinField4 = obj_i.SomeField4
        } 
        equals 
        new { 
          JoinField1 = obj_j.SomeOtherField1,
          JoinField2 = obj_j.SomeOtherField2,
          JoinField3 = obj_j.SomeOtherField3,
          JoinField4 = obj_j.SomeOtherField4
        }

But I was recently told that the below is also ‘another way’ of writing LINQ queries.

var query =     
    from obj_i in set1
    join obj_j in set2 on       
    obj_i.SomeField1 = obj_j.SomeOtherField1 and
    obj_i.SomeField2 = obj_j.SomeOtherField2 and
    obj_i.SomeField3 = obj_j.SomeOtherField3 and
    obj_i.SomeField4 = obj_j.SomeOtherField4

As I understand, using the single = is wrong (especially in the case where by == doesn’t apply since you need to use equals, but also using and is wrong, since the correct keyword would be && if you were allowed to use anything but equals in this case.

I can understand the use of && and == in the where clause, which makes it even more outstanding that the above code can be used, since it doesn’t even compile.

Am I missing something?
If so, could you point me to where I can learn of this alternate method of writing LINQ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:23:49+00:00Added an answer on June 4, 2026 at 9:23 am

    But I was recently told that the below is also ‘another way’ of writing LINQ queries.

    No, the second syntax you show is incorrect. Just try it, you’ll see that it doesn’t compile.

    The join clause in Linq query comprehension syntax is translated to a call to the Join extension method. For instance, this query:

    var query =
        from x in a
        join y in b
        on x.Foo equals y.Bar
        select Baz(x, y);
    

    Is translated to:

    var query = a.Join(b, x => x.Foo, y => y.Foo, (x, y) => Baz(x, y));
    

    So you can see that the parts on the left and right of equals correspond to different parameters of the Join method: the left part selects the join key for the first source, and the right part selects the key for the second source. These keys are then matched against each other to perform the join. This is the important part: the on clause doesn’t specify a free-form join condition, it specifies how to extract the join key on each side. So the left and right key selectors have to be clearly separated; the second syntax you show can’t work, because there’s no way to extract full key information for either source: the join could only be performed by evaluating the join condition for each (x, y), which is an O(n²) operation instead of a (roughly) O(n) operation.

    However, sometimes you need more flexibility than what an equi-join can give; in that case you can use a cross-join and filter the results:

    var query =
        from x in a
        from y in b
        where x.Foo == y.Bar
        select Baz(x, y);
    

    Or in your case:

    var query =     
        from obj_i in set1
        from obj_j in set2
        where obj_i.SomeField1 == obj_j.SomeOtherField1
        &&    obj_i.SomeField2 == obj_j.SomeOtherField2
        &&    obj_i.SomeField3 == obj_j.SomeOtherField3
        &&    obj_i.SomeField4 == obj_j.SomeOtherField4;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.