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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:46:09+00:00 2026-05-11T02:46:09+00:00

I have the following class objects: public class VacancyCategory { public int ID {

  • 0

I have the following class objects:

    public class VacancyCategory {     public int ID { get; set; }     public string Text { get; set; }     public IList<VacancySubCategory> SubCategories { get; set; } }      public class VacancySubCategory {     public int ID { get; set; }     public string Text { get; set; }     public VacancyCategory Category { get; set; }     public IList<Vacancy> Vacancies { get; set; } }      public class Vacancy : IBusinessObject {     public int ID { get; set; }     public string Title { get; set; }     public VacancySubCategory SubCategory { get; set; }     public string Body { get; set; }     public VacancyWorkType WorkType { get; set; }     public string Salary { get; set; }     public DateTime? AppsClosingDate { get; set; }     public bool Active { get; set; } } 

…so in a test repository im creating test data like so:

        private IList<VacancyCategory> GetVacancyCategoriesWithAllChildCollections()     {         IList<VacancyCategory> vacancyCategories = new List<VacancyCategory>();          int cCounter = 0;         int scCounter = 0;         int vCounter = 0;         for (int i = 1; i <= 3; i++)         {             VacancyCategory vc = new VacancyCategory();             vc.ID = ++cCounter;             vc.Text = 'VacancyCategory' + i.ToString();              for (int j = 1; j <= 3; j++)             {                 VacancySubCategory vsc = new VacancySubCategory();                 vsc.ID = ++scCounter;                 vsc.Text = 'VacancySubCategory' + scCounter.ToString();                 vsc.Category = vc;                  for (int k = 1; k <= 2; k++)                 {                     Vacancy v = new Vacancy();                     v.ID = ++vCounter;                     v.Title = 'Vacancy' + vCounter.ToString();                     v.Body = 'VacancyBody' + vCounter.ToString();                     v.Active = vCounter >= 16 ? false : true;                     v.WorkType = this._workTypes.Single(wt => wt.ID == k);                     v.Salary = vCounter <= 7 ? 'SR ' + (vCounter * 1000).ToString() : '';                     v.AppsClosingDate = (vCounter >= 3 & vCounter <= 13) ? (new DateTime(2009, 3, vCounter)) : (DateTime?)null;                     v.SubCategory = vsc;                      if (vsc.Vacancies == null)                         vsc.Vacancies = new List<Vacancy>();                     vsc.Vacancies.Add(v);                 }                  if (vc.SubCategories == null)                     vc.SubCategories = new List<VacancySubCategory>();                 vc.SubCategories.Add(vsc);             }              vacancyCategories.Add(vc);         }          return vacancyCategories;     } 

..so now i have some good test data. the object tree / chained objects are important to me.

so i’d like to return the individual object collections from this tree when desired. for example, if i wanted the whole tree, i can just return the VacancyCategory list with all the child objects – great. but now i want to return just the VacancySubCaregory items (all 9 of them). this would be my public method to the test repository:

        public IQueryable<VacancySubCategory> GetVacancySubCategories()     {           throw new NotImplementedException('write gen code');     } 

.. obviously without the exception. i have a member field called _categories that contains the results from the GetVacancyCategoriesWithAllChildCollections method. so i’ve been trying stuff like

this._categories.Select( ...... 

..but i cant seem to return a list of VacancySubCategory objects. i seem to always be selecting the root collection (ie. a result set of VacancyCategory objects). What am i doing wrong? im sure its simple… but its driving me nuts!

EDIT

thanx matt.

your suggestion led me to this:

        public IQueryable<VacancySubCategory> GetVacancySubCategories()     {         return this._categories.SelectMany(c => c.SubCategories).AsQueryable<VacancySubCategory>();     } 

..which works great. you’re a champ

  • 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. 2026-05-11T02:46:09+00:00Added an answer on May 11, 2026 at 2:46 am

    Try:

    return this._categories.SelectMany(c => c.SubCategories); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following objects: public class User { int Id { get; set;
Have the following: class Hal { public int zip { get; set; } public
I have the following object model: class ObjectA{ public string Description {get;set;} } class
I have the following class: public class Foo { public int Id { get;
I have a following class public class People { public int id; public string
I have the following business objects: public abstract class Product { public int Id
i have the following two objects public partial class ProgramObj { public int id;
I have a question on constant objects. In the following program: class const_check{ int
I have the following database tables/EF objects public class Transaction { //some other properties
Say you have the following class public class AccessStatistics { private final int noPages,

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.