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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:13:58+00:00 2026-05-29T17:13:58+00:00

Assuming I have an Entity Framework 4.2 class like this: class Company { public

  • 0

Assuming I have an Entity Framework 4.2 class like this:

class Company
{
    public int ID { get; set; }
    public ICollection<Employee> Employees { get; set; }
}

And I have collection like this:

public ICollection<Company> Companies { get; set; }

What’s an efficient way to build a list of all employees in the entire Companies collection? I do not need to worry about duplicates.

Note: I’m trying to do it without an Entity Framework context–just using the Companies collection. However, if this entails a huge performance hit, I could get a context if necessary.

  • 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-29T17:14:01+00:00Added an answer on May 29, 2026 at 5:14 pm

    I’m not sure what you’re trying to achieve, but to query the data you’ll want to use the DbContext.

    You can configure you context to automatically load the related entities by setting LazyLoadingEnabled to true, or explicitly, i.e. when querying the data, include the path to the employees, using the Include extension provided with EF > 4.0.

    As soon as all companies are there you could linq it using the SelectMany method. I haven’t checked, but AFAIK, LINQ to SQL will execute the query as one bunch on demand.

    If you insist not to expose your DbContext or if you use a different underlying context, I would suggest you to wrap it up in a repository that does the SelectMany behind the since, but your friend are Include and SelectMany.

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

Sidebar

Related Questions

I have the following Entity Framework POCO classes: public class Customer { public int
I have a standard Domain Layer entity: public class Product { public int Id
Assuming I have a class A as follows: class A{ int id; int getId(){};
I have a groovy DSL script like this: entity(attribute1:one, attribute2:two) so far so good.
I have a save function for my order entity that looks like this and
Assuming I have only the class name of a generic as a string in
how do I return the entity ID using python in GAE? Assuming I have
I am trying to pre-generate view metadata for my Entity Framework project and have
I have two classes an Arc class and a Line class public class Arc
I have a database I'd like to create an entity from, and then generate

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.