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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:42:28+00:00 2026-05-16T03:42:28+00:00

We have 3 tables in our db that each have an entity in our

  • 0

We have 3 tables in our db that each have an entity in our edmx. To illustrate my problem, imagine 3 tables:

Table: Make
Fields:
makeID
make

Table: Model
FIelds:
modelID
makeID    foreign key
model

Table: Car
carID
modelID   foreign key
car

Our Make, Model, and Car entity have all of the navigation properties in the entity model. Lazy loading is disabled. We want to be able to pull all cars that are Jeep Grand Cherokees to output to our page.

Right now we have something like this in one of our functions (C# 4.0)

IEnumerable<Make> makeList =  (((ObjectSet<Lot>)_modelRepository.GetQuery())
         .Include(mk => mk.Models.Where(md => md.model == "Grand Cherokee"))
         .Where(mk => mk.make == "Jeep").ToList());

_makeRepository.GetQuery() returns an IQueryable … we implement the repository pattern

This query should work fine (haven’t tested it, created for ths example) but how can we .Include the car table so that our function returns Make entity objects such that the Model is populated and the Cars are populated (problem getting the Cars because they do not have a direct navigation property to Make)

We’re using POCO objects.

The goal is to have 1 function returning a Make entity to be able to do this:

foreach(Make myMake in makeList)
{
    Response.Write(myMake.make);

    foreach(Model myModel in myMake.Models)
    {
         Response.Write(myModel.model);

         foreach(Car mycar in myModel.Cars)
         {
              Response.Write(mycar.car);
         }
    }
}

Something like this doesn’t seem possible but its what we’re going for:

IEnumerable<Make> makeList =  (((ObjectSet<Lot>)_modelRepository.GetQuery())
         .Include(mk => mk.Models.Where(md => md.model == "Grand Cherokee"))
         .Include(c => mk.Models.Cars)
         .Where(mk => mk.make == "Jeep").ToList());

I’ve also tried creating a new entity in my edmx that contains all of this information so that I can just query that one object but I keep getting errors saying keys must be mapped… I did map them in the Mapping tab (Visual Studio 2010)… so I’m back to trying to get the query working.

  • 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-16T03:42:29+00:00Added an answer on May 16, 2026 at 3:42 am

    I am not 100% sure but I believe you are going to need to create some kind of DTO like this:

    public MakeModelCarDto
    {
        public IEnumerable<Make> Makes {get; set;}
        public IEnumerable<Model> Models {get; set;}
        public IEnumerable<Car> Cars {get; set;}
    }
    

    Then you are going to have to JOIN the tables like this:

    _makeRepository.GetQuery()
            .Join(_modelRepository.GetQuery(), mk => mk.makeid, mo => mo.makeid, (mk, mo) => new { mk, mo })
            .Join(_carRepository.GetQuery(), @t => @t.mo.modelid, c => c.modelid, (@t, c) => new { @t, c })
            .Where(@t => @t.@t.mk.make == "Jeep" && @t.@t.mo.model == "Grand Cherokee")
            .Select(@t => new MakeModelCarDto
            {
                Makes = @t.@t.mk,
                Model = @t.@t.mo,
                Cars = @t.c
            }).SingleOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a table that is used for assessment-values in our tool where each
We have two tables in our application that both have a ShowOrder column. We
I have tables linked by FK, I query on the first table using entity
I have a table that has a bunch of fields. The fields can be
I have 2 classes that reference each other. It's a weird situation that our
We have built an internal tool that generates the whole data access, each table
Our client's request is to have tables in PDF with rounded corner. I only
We've encountered the following situation in our database. We have table 'A' and table
I have a table containing data about some users. Many of them use our
In iOS apps, we have to register nib files with our table view before

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.