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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:46:33+00:00 2026-05-30T11:46:33+00:00

I am joining 2 in memory collections var items = from el in elements

  • 0

I am joining 2 in memory collections

var items = 
    from el in elements 
    join def in Cached.Elements() 
        on el.Value equals def.Name into temp1
    from res in temp1.DefaultIfEmpty()                        
    select new
    {
        el.NodeType, 
        res.DefKey, 
        res.DefType, 
        res.BaseKey, 
        el.Value 
    };

However, ideally if one of the elements can’t be found, I’d like to raise an exception, something akin to

throw new System.Exception(el.Value + " cannot be found in cache!");

I was looking at the System.Interactive which offers a Catch extension method but I am unsure how to reference the current ‘el’ in that context. So for example I was wondering about something like

    var items = (
        from el in elements 
        join def in Cached.Elements() 
            on el.Value equals def.Name into temp1
        from res in temp1.DefaultIfEmpty()                        
        select new 
        { 
            el.NodeType, 
            res.DefKey, 
            res.DefType, 
            res.BaseKey, 
            el.Value 
        })
        .ThrowIfEmpty();

but, istm, that that would entail passing the whole set into the extension method rather than raising the exception when the missing value is encountered.

Alternatively, I could replace the DefaultIfEmpty with a ThrowIfEmpty

    var items = (
        from el in elements 
        join def in Cached.Elements() 
            on el.Value equals def.Name into temp1
        from res in temp1.ThrowIfEmpty()                        
        select new 
        { 
            el.NodeType, 
            res.DefKey, 
            res.DefType, 
            res.BaseKey, 
            el.Value 
        });

Is there a ‘proper’/better way to do this?

  • 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-30T11:46:34+00:00Added an answer on May 30, 2026 at 11:46 am

    You can use GroupJoin. Something like this should work for you:

    elements.GroupJoin(Cached.Elements(), e => e.Value, d => d.Name, (e, dSeq) => {
        var d = dSeq.Single();
        return new { e, d };
    });
    

    The GroupJoin resultSelector accepts two arguments: the left key, and the sequence of matching right keys. You can raise an exception if the sequence is empty; one way to achieve that would be to use the Single operator.

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

Sidebar

Related Questions

i'm joining tables like: select * from tableA a full join tableB b on
I'm JOINing the results of this query: SELECT twitter_personas.id , 'TwitterPersona' , twitter_personas.name FROM
I am LEFT JOINing multiple tables as such: SELECT * FROM table1 LEFT JOIN
Working on joining up two legacy DB systems into new database where I can
Joining a list: >>> ''.join([ str(_) for _ in xrange(10) ]) '0123456789' join must
Joining data from different tables and displaying them in ordered manner using xslt: I
i have problem when joining tables(left join) table1: id1 amt1 1 100 2 200
I'm having a trouble filtering/ joining in-memory object lists with Linq to objects, and
I'm joining to a table dozens of different times, and every time, I join
i am joining 2 tables using this query SELECT DISTINCT (member.id), member_type FROM member

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.