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

  • Home
  • SEARCH
  • 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 7767271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:38:07+00:00 2026-06-01T15:38:07+00:00

Came across a problem whereby I wanted the last time data was imported to

  • 0

Came across a problem whereby I wanted the last time data was imported to show failures. I ended up resorting to HQL because I had to execute two queries can anyone see why this doesn’t work (properly) in Linq to NHibernate, is it a known bug in 3.1?

The sql I would write.

select JobImport.* from 
JobImportResult
inner join (
    select Max(JobImportResultId) as JobImportResultId 
    from JobImportResult
    group by JobImportId
)as tbl on tbl.JobImportResultId = JobImportResult.JobImportResultId
inner join JobImport on JobImport.JobImportId = JobImportResult.JobImportId
where ImportFailureReasonId is not null

The HQL I ended up writing.

select jir.JobImport from JobImportResult jir where jir.Id in 
(select max(mjir.Id) from JobImportResult mjir group by mjir.JobImport)
and jir.ImportFailureReason is not null

The Linq that works(but I think will break after 2000 rows)

var innerQuery = Query<JobImportResult>()
    .GroupBy(jir=>jir.JobImport)
    .Select(jir=>jir.Max(jr=>jr.Id));

var innerQueryListed = innerQuery.ToList();

var resultQuery = Query<JobImportResult>()
    .Where(jir => innerQueryListed.Contains(jir.Id) && jir.ImportFailureReason != null)
    .Select(jir => jir.JobImport);

The Linq that doesn’t work 🙁

var innerQuery = Query<JobImportResult>()
.GroupBy(jir=>jir.JobImport)
.Select(jir=>jir.Max(jr=>jr.Id));

var resultQuery = Query<JobImportResult>()
.Where(jir => innerQuery.Contains(jir.Id) && jir.ImportFailureReason != null)
.Select(jir => jir.JobImport);
  • 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-01T15:38:09+00:00Added an answer on June 1, 2026 at 3:38 pm

    Are you using .NET 4? If so, try this:

    var innerQuery = Query<JobImportResult>()
        .GroupBy(jir=>jir.JobImport)
        .Select(jir=>jir.Max(jr=>jr.Id))
        .ToList();
    
    var resultQuery = Query<JobImportResult>()
        .Where(jir => innerQuery.Any(j => j == jir.Id)
            && jir.ImportFailureReason != null)
        .Select(jir => jir.JobImport)
        .ToList(); //only use this if you want to resolve the query
    

    Or .NET 3.5 change the resultQuery part to be:

    var resultQuery = Query<JobImportResult>()
        .Where(jir => innerQuery.Count(j => j == jir.Id) > 0
            && jir.ImportFailureReason != null)
        .Select(jir => jir.JobImport)
        .ToList(); //only use this if you want to resolve the query
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, it's finals time and I came across this problem in an old exam:
I came across a problem and can not move forward because I cannot get
I have recenty came across a problem while importing older data than my current
I came across a problem in my current application that required fiddling with the
I came across this problem while preparing for an interview and curious to know
I came across a problem I cannot solve on my own concerning the downloadable
I came across this problem when trying to decode json into an array ,
i came across this problem, my code in the viewWillAppear method is not executed
Today I came across a problem where someone had accidentally committed a proj.user file
I am new to creating Java web applications and came across this problem when

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.