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 3307642
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:25:47+00:00 2026-05-17T21:25:47+00:00

I have a linq union statement that has been giving me some trouble and

  • 0

I have a linq union statement that has been giving me some trouble and I can’t see where the issue is. Any help would be appreciated.

The error is….
All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.

I know the error means that I am selecting different amounts of elements in one of the linq statements, but I’ve examined this query extensively and I haven’t been able to see that as the issue.

(From m In db.mainIncidents _
                                    Join r In db.rcas On r.reliabilityID Equals m.reliabilityID _
                                    Join team In db.rcaInvestigationTeams On team.rcaID Equals r.rcaID _
                                    Join user In db.sysUsers On team.teamMemberID Equals user.sysUserID _
                                    Where m.reliabilityID = reliabilityID _
                                    And team.deleted = False _
                                    Select name = user.firstName & " " & user.lastName & " (" & user.id.ToUpper & ")", _
                                    email = user.id & "@test.com", _
                                    user.phone, _
                                    isSponsor = "No", _
                                    isFacilitator = "No", _
                                    isAssetTeamLead = "No").Union _
                               (From m In db.mainIncidents _
                                    Join r In db.rcas On r.reliabilityID Equals m.reliabilityID _
                                    Join at In db.sysUsers On r.assetTeamLeadID Equals at.sysUserID _
                                    Where m.reliabilityID = reliabilityID _
                                    Select name = at.firstName & " " & at.lastName & " (" & at.id.ToUpper & ")", _
                                    email = at.id & "@test.com", _
                                    at.phone, _
                                    isSponsor = "No", _
                                    isFacilitator = "No", _
                                    isAssetTeamLead = "Yes").Union _
                              (From m In db.mainIncidents _
                                    Join r In db.rcas On r.reliabilityID Equals m.reliabilityID _
                                    Join f In db.sysUsers On r.facilitatorID Equals f.sysUserID _
                                    Where m.reliabilityID = reliabilityID _
                                    Select name = f.firstName & " " & f.lastName & " (" & f.id.ToUpper & ")", _
                                    email = f.id & "@test.com", _
                                    f.phone, _
                                    isSponsor = "No", _
                                    isFacilitator = "Yes", _
                                    isAssetTeamLead = "No").Union _
                              (From m In db.mainIncidents _
                                    Join r In db.rcas On r.reliabilityID Equals m.reliabilityID _
                                    Join s In db.sysUsers On r.sponsorID Equals s.sysUserID _
                                    Where m.reliabilityID = reliabilityID _
                                    Select name = s.firstName & " " & s.lastName & " (" & s.id.ToUpper & ")", _
                                    email = s.id & "@test.com", _
                                    s.phone, _
                                    isSponsor = "No", _
                                    isFacilitator = "No", _
                                    isAssetTeamLead = "No")
  • 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-05-17T21:25:47+00:00Added an answer on May 17, 2026 at 9:25 pm

    I can’t find the issue in the query. I’ve used LINQPad and run your query against an adhoc object model and it runs without complaint.

    The only thing I can suggest is to remove the repetition. Hopefully then the error will no longer be there.

    Here’s my factoring.

    I do a single db.sysUsers query:

    Dim users =
        From u In db.sysUsers
        Select New With { _
            .userId = u.id, _
            .name = u.firstName & " " & u.lastName & " (" & u.id.ToUpper & ")", _
            .email = u.id & "@test.com", _
            .phone = u.phone }
    

    I do a single query on db.mainIncidents & db.rcas:

    Dim rcas =
        From m In db.mainIncidents _
        Where m.reliabilityID = reliabilityID _
        Join r In db.rcas On r.reliabilityID Equals m.reliabilityID _
        Select r
    

    And here’s the best part, a Role query:

    Dim roles =
        From r In rcas _
        From role in ( _
        { _
            New With { .userId = r.assetTeamLeadID, .role = "AssetTeamLead" }, _
            New With { .userId = r.facilitatorID, .role = "Facilitator" }, _
            New With { .userId = r.sponsorID, .role = "Sponsor" } _
        }).Concat(From team In db.rcaInvestigationTeams _
            Where team.deleted = False _
            Where team.rcaID = r.rcaID _
            Select New With { .userId = team.teamMemberID, .role = "TeamMember" }) _
        Select role
    

    And now, the final query:

    Dim query =
        From u In users _
        Join r In roles On u.userId Equals r.userId _
        Select u.name, u.email, u.phone, _
        isSponsor = If(r.role = "Sponsor", "Yes", "No"), _
        isFacilitator = If(r.role = "Facilitator", "Yes", "No"), _
        isAssetTeamLead = If(r.role = "AssetTeamLead", "Yes", "No")
    

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some LINQ code that generates a list of strings, like this: var
I know that Entity Framework has some LINQ support problems (at least in comparison
I have LINQ statement that looks like this: return ( from c in customers
Assume that you have two IEnumerbale objects. How we can merge them (in some
I have a LINQ to Entity query that is running really slow. This query
I have a Linq expression that (for northwind) gets the total qty ordered per
I have a Linq query that looks something like this: var myPosse = from
I have this linq query that works well (although it may be written better,
I have a Linq query that looks something like this: var query = from
I have a perplexing SQL select statement (ugly) that I'm trying to write in

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.