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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:07:24+00:00 2026-05-27T12:07:24+00:00

I have had a look at this Flatten LINQ collection object with nested object

  • 0

I have had a look at this Flatten LINQ collection object with nested object collections but it doesn’t quite do it for me.

I know there is a lot of code in this post but it’s mostly just data to give you the idea of what I’m looking at developing.

if you look at the classes below, I am trying to come up with a way to flatten the result of a search against the file.

So i need to end up with a single flattened record which looks like (the pipes are there to show delimination of a field only)

fileId | FileContact1FirstName | FileContact1LastName | FileContact2FirstName etc | FileClient1FirstName  | FileClient1LastName | FileClient1IsNominee | FileClient1IsPrimary | FileClient2FirstName etc....

Any idea on how I can do this without looping through each Contact and Client?

I have these classes of sorts in my edmx;

class File
{
    public int fileId { get; set; }
    public List<FileContact> fileContacts { get; set; }
    public List<FileClient> fileClients { get; set; }
}

class FileContact
{
    public Contact contact { get; set; }
}

class FileClient
{
    public Contact contact { get; set; }
    public bool IsNominee { get; set; }
    public bool IsPrimary { get; set; }
}

class Contact
{
    public int id { get; set; }
    public string firstName { get; set; }
    public string lastName { get; set; }
}

And this this as the data simply for testing.

    static void FillData()
    {
        thisFile = new File { fileId = 1, fileContacts = new List<FileContact>(), fileClients = new List<FileClient>() };

        thisFile.fileContacts.Add(new FileContact { contact = new Contact { id = 1, firstName = "Andrew", lastName = "Albino" } });
        thisFile.fileContacts.Add(new FileContact { contact = new Contact { id = 1, firstName = "Bob", lastName = "Bush" } });
        thisFile.fileContacts.Add(new FileContact { contact = new Contact { id = 1, firstName = "Cathy", lastName = "Conti" } });
        thisFile.fileContacts.Add(new FileContact { contact = new Contact { id = 1, firstName = "Drew", lastName = "Dram" } });
        thisFile.fileContacts.Add(new FileContact { contact = new Contact { id = 1, firstName = "Edward", lastName = "Eliston" } });
        thisFile.fileContacts.Add(new FileContact { contact = new Contact { id = 1, firstName = "Frank", lastName = "Fashion" } });
        thisFile.fileContacts.Add(new FileContact { contact = new Contact { id = 1, firstName = "Graham", lastName = "Grape" } });

        thisFile.fileClients.Add(new FileClient { contact = new Contact { id = 1, firstName = "Harry", lastName = "Who didn't" }, IsNominee = true, IsPrimary = false });
        thisFile.fileClients.Add(new FileClient { contact = new Contact { id = 1, firstName = "Indigo", lastName = "Ignacio" }, IsNominee = false, IsPrimary = false });
        thisFile.fileClients.Add(new FileClient { contact = new Contact { id = 1, firstName = "Julie", lastName = "Juniper" }, IsNominee = false, IsPrimary = false });
        thisFile.fileClients.Add(new FileClient { contact = new Contact { id = 1, firstName = "Kelly", lastName = "Keilor" }, IsNominee = false, IsPrimary = false });
        thisFile.fileClients.Add(new FileClient { contact = new Contact { id = 1, firstName = "Liam", lastName = "Loser" }, IsNominee = false, IsPrimary = true });
    }
}
  • 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-27T12:07:25+00:00Added an answer on May 27, 2026 at 12:07 pm

    This will get you an IEnumerable<string> that contains the properties in the order you specified:

    var flattened = new string[] { thisFile.fileId.ToString() }
    .Concat(
        thisFile.fileContacts
        .SelectMany(fc => new string[] 
        { 
            fc.contact.firstName, 
            fc.contact.lastName 
        }))
    .Concat(
        thisFile.fileClients
        .SelectMany(fc => new string[] 
        { 
            fc.contact.firstName, 
            fc.contact.lastName, 
            fc.IsNominee.ToString(), 
            fc.IsPrimary.ToString() 
        }));
    

    Example: http://ideone.com/Mvc7M

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

Sidebar

Related Questions

I know this is probably rather trivial but I have had a look at
Apologies if this was already asked but, I have had a look and can't
im sorry if this has already been covered, i have had a look but
I have had a look to see if this has been answered but to
I have had a look at this link: https://www.owasp.org/index.php/Input_Validation_Cheat_Sheet which discuss the use of
I am a long time C# developer and have had to look at some
I have had a few problems getting this right, so I wanted to ask
I have had no luck with this task so far so grateful for any
I have had this problem w/ two seperate WYSWYG editors in my rails application
I have had a look around online to try and find out the best

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.