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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:04:34+00:00 2026-06-07T19:04:34+00:00

I’m working on a problem that’s making my brain melt although I don’t think

  • 0

I’m working on a problem that’s making my brain melt although I don’t think it should be this hard. My example is long so I’ll try to keep my question short!

I have an Array object that contains some elements that are also Arrays. For example:

customerAddresses = new customer_address[]
{
  new    // address #1
  {
    customer_id = 6676979,
    customer_address_seq = 1,
    customer_address_match_codes = new []
    {
      new
      {
        customer_address_seq = 1,
        customer_id = 6676979,
        customer_match_code_id = 5
      }
    }
  },
  new    // address #2
  {
    customer_id = 6677070,
    customer_address_seq = 1,
    customer_address_match_codes = new []
    {
      new
      {
        customer_address_seq = 1,
        customer_id = 6677070,
        customer_match_code_id = 4
      },
      new
      {
        customer_address_seq = 1,
        customer_id = 6677070,
        customer_match_code_id = 5
      },
      new
      {
        customer_address_seq = 1,
        customer_id = 6677070,
        customer_match_code_id = 3
      }
    }
  },
  new    // address #3
  {
    customer_id = 6677070,
    customer_address_seq = 2,
    customer_address_match_code = new []
    {
      new
      {
        customer_address_seq = 2,
        customer_id = 6677070,
        customer_match_code_id = 4
      },
      new
      {
        customer_address_seq = 2,
        customer_id = 6677070,
        customer_match_code_id = 5
      }
    }
  }
};

As you can see, the Array contains a number of address records, with one record per combination of customer_id and customer_address_seq. What I’m trying to do is find the best matching customer_address according to the following rules:

  • There must be customer_match_code_id equal to 4 and there must be one equal to 5
  • If there is a customer_match_code_id equal to 3, then consider that customer_address a stronger match.

According to the above rules, the 2nd customer_address element is the “best match”. However, the last bit of complexity in this problem is that there could be multiple “best matches”. How I need to handle that situation is by taking the customer_address record with the minimum customer_id and minimum customer_address_seq.

I was thinking that using LINQ would be my best bet, but I’m not experienced enough with it, so I just keep spinning my wheels.

  • 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-07T19:04:36+00:00Added an answer on June 7, 2026 at 7:04 pm

    Had to make a change to your class so that you are actually assigning your one collection to something:

    customer_address_match_codes = new customer_address_match_code[]
    {
      new
      {
        customer_address_seq = 1,
        customer_id = 6676979,
        customer_match_code_id = 5
      }
    }
    

    And then here is the LINQ that I’ve tested and does what you specify:

    var result = (from c in customerAddresses
        let isMatch = c.customer_address_match_codes
                         .Where (cu => cu.customer_match_code_id == 4).Any () &&
                      c.customer_address_match_codes
                         .Where (cu => cu.customer_match_code_id == 5).Any ()
        let betterMatch = isMatch && c.customer_address_match_codes
                      .Where (cu => cu.customer_match_code_id == 3).Any () ? 1 : 0
        where isMatch == true
        orderby betterMatch descending, c.customer_id, c.customer_address_seq
        select c)
        .FirstOrDefault ();
    

    I’ve worked up an example using your data with anonymous types here: http://ideone.com/wyteM

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
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
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.