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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:41:59+00:00 2026-06-04T10:41:59+00:00

I think I have got myself into a muddle with this one. My database

  • 0

I think I have got myself into a muddle with this one. My database looks like:

Locations [root]
    Inspections [level1]
       InspectionItems [level2]
           InspectionReadings [level3]      
    Areas [level1]
       Inspections [level2]
           InspectionItems [level3]
               InspectionReadings [level4]

each table is linked by Guid to the previous table and the Inspections table has nullable AreaID so that it can be a direct child of Locations.

What I need is

for each Location 
    {take all InspectionReadings entities
     where location == location
     sort date descending 
     return the top Entity details}
add the Location details and the InspectionReading details into a new table
return new table

the result should be a datagrid with a list of locations and their latest inspection reading date. each location should only appear once.

What I have managed is (this is in my DomainService.cs)

        public IQueryable<LocationStatusList> GetLocationStatus()
        {
         var status = (from a in ObjectContext.Locations
                      from b in ObjectContext.InspectionReadings
                      orderby b.DateTaken descending, a.Name 
                      select new LocationStatusList()
                      {
                          ID = b.ID,
                          LocationName = a.Name,
                          LastInspectionDate = b.DateTaken ?? DateTime.MinValue, // the data is nullable so it needs a value to return in that case
                          StatusNumber = b.Status ?? -1 // the data is nullable so it needs a value to return in that case
                      });
         return status;
        }

which returns the entire InspectionItems entities with their relevant location and although I’ve tried I can’t find a way of doing what I need.

I would like to do all the code for this in the DomainService class but the only way I can think at the moment is to give the query each location name as a parameter from a viewmodel, return a single entity and create a new list and add each single entity.

Surely this can all be done in a LINQ query?

  • 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-04T10:42:00+00:00Added an answer on June 4, 2026 at 10:42 am

    Final version, if I get it right:

    var status = (from a in ObjectContext.Locations
                  select new {Location = a, LastReading = a.Inspections.SelectMany(i=>i.InspectionReadings).OrderBy(r=>r.PostDate).FirstOrDefault()};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I have this working but I need advice. I'd like to know
I have recently got myself into learning PHP. I have a mac and the
I've got a trait that looks like this (some further information can be found
I've got myself into a bit of predicament where I have a fixed width
I have studied generators feature and i think i got it but i would
I have found myself with at little problem, and I think a custom model
I think I've worked myself into a pretty stupid corner, here. Let me show
Ok, so i have got myself completely stuck. My search skill are lacking and
I got myself into a little bit of a local repo mess. Long story
Ok, in hindsight this does seem to be a silly problem I got myself

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.