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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:44:37+00:00 2026-06-19T02:44:37+00:00

I have the following linq query public IEnumerable<DealershipWithDealersViewModel> Get(float latitude, float longitude) { return

  • 0

I have the following linq query

public IEnumerable<DealershipWithDealersViewModel> Get(float latitude, float longitude)
        {
            return from dealer in Db.Dealerships
                          join i in Db.NearestDealers(latitude, longitude)
                          on dealer.DealerID equals i.DealerID
                          select new DealershipWithDealersViewModel
                                     {
                                         DealerID = dealer.DealerID,
                                         Dealer = dealer.Dealer,
                                         DoSales = dealer.DoSales,
                                         DoService = dealer.DoService,
                                         AddressProvinceID = dealer.AddressProvinceID,
                                         AddressLocationID = dealer.AddressLocationID,
                                         Address1 = dealer.Address1,
                                         Address2 = dealer.Address2,
                                         Tel = dealer.Tel,
                                         Fax = dealer.Fax,
                                         MapLat = dealer.MapLat,
                                         MapLong = dealer.MapLong,
                                         Location = dealer.Location.LocationName,
                                         DealerUsers = dealer.DealerUsers
                                            .Select(y => new DealerUserViewModel
                                                             {
                                                                DealerUserID = y.DealerUserID,
                                                                FirstName  = y.Firstname,
                                                                Surname = y.Surname,
                                                                LandLine = y.LandLine,
                                                                Email = y.Email,
                                                                Position = y.DealerType.DealerPosition
                                                             })

                                     };
        }

enter image description here
I keep getting the following error The nested query does not have the appropriate keys. I cannot find anything about it on the net. If I load the above without DealerUsers, it works as expected, but I need the nested data. Thank you! The below works by the way.

public IEnumerable<DealershipWithDealersViewModel> Get(float latitude, float longitude)
        {
            return from dealer in Db.Dealerships
                          join i in Db.NearestDealers(latitude, longitude)
                          on dealer.DealerID equals i.DealerID
                          select new DealershipWithDealersViewModel
                                     {
                                         DealerID = dealer.DealerID,
                                         Dealer = dealer.Dealer,
                                         DoSales = dealer.DoSales,
                                         DoService = dealer.DoService,
                                         AddressProvinceID = dealer.AddressProvinceID,
                                         AddressLocationID = dealer.AddressLocationID,
                                         Address1 = dealer.Address1,
                                         Address2 = dealer.Address2,
                                         Tel = dealer.Tel,
                                         Fax = dealer.Fax,
                                         MapLat = dealer.MapLat,
                                         MapLong = dealer.MapLong,
                                         Location = dealer.Location.LocationName

                                     };
        }

enter image description here

Update

This also works.

return Db.Dealerships.Select(x => new DealershipWithDealersViewModel
            {
                DealerID = x.DealerID,
                Dealer = x.Dealer,
                DoSales = x.DoSales,
                DoService = x.DoService,
                AddressProvinceID = x.AddressProvinceID,
                AddressLocationID = x.AddressLocationID,
                Address1 = x.Address1,
                Address2 = x.Address2,
                Tel = x.Tel,
                Fax = x.Fax,
                MapLat = x.MapLat,
                MapLong = x.MapLong,
                Location = x.Location.Location1,
                DealerUsers = x.DealerUsers.Select(y => new DealerUserViewModel
                                                            {
                                                                DealerUserID = y.DealerUserID,
                                                                FirstName = y.Firstname,
                                                                Surname = y.Surname,
                                                                LandLine = y.LandLine,
                                                                Email = y.Email,
                                                                Position = y.DealerType.DealerType1
                                                            })
            });

enter image description here

  • 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-19T02:44:38+00:00Added an answer on June 19, 2026 at 2:44 am

    It’s a matter of composablity. EF will always try to translate your query into SQL. If this succeeds, fine. If it doesn’t, it’s not going to try and make it work e.g. by switching to linq to objects below the hood (as linq to sql may do). You trying to join a stored procedure result to a SQL query. This can’t even be done in plains SQL, because sproc results are not composable, let alone by EF.

    You van only join the results in memory, by using Db.Dealerships.AsEnumerable() and Db.NearestDealers(latitude, longitude).

    So it would be very useful if you could add a filter parameter DealerID to the procedure’s signature.

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

Sidebar

Related Questions

I have this following IEnumerable LINQ query: var query = from p in Enumerable.Range(2,
I have the following method: public IEnumerable<Foo> GetFoo(int x, string y) { return from
I have a LINQ query that looks like this: public IEnumerable<Foo> SelectFooBars() { return
I have the following LINQ query: var queryGroups = (from p in db.cl_contact_event select
I have the following LINQ query: From metasect In DirectCast(Form.ChildDocBox.Tag, META_DOCUMENT).META_SECTIONS From metaset In
I have the following linq query (applied to the Northwind database) (from od in
I have the following XML LINQ query from my XDocument. var totals = (from
I have the following Nhibernate LINQ query: var query = from c in session.Query<Customer>()
I have the following LINQ query that returns two objects from my database. These
I have the following Linq query: List<MonthlySales> monthlySales = (from sale in Sales group

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.