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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:41:51+00:00 2026-05-27T01:41:51+00:00

I am looking at nHibernate and Entity Framework as possible ORMs to introduce into

  • 0

I am looking at nHibernate and Entity Framework as possible ORMs to introduce into a system. I am trying to perform the equivalent to the following SQL using nHibernate:

SELECT
   a.Id,
   a.Name,
   a.Etc,
   MAX(CASE WHEN (c.dId IS NOT NULL) THEN 1 ELSE 0 END) As IsLinked
FROM
   tA a
   INNER JOIN tAB ab ON a.Id = ab.aId
   INNER JOIN tB b ON ab.bId = b.Id
   LEFT OUTER JOIN tC c ON b.cId = c.Id
   AND c.dId = 'x'
WHERE
   a.Id = 'y'
GROUP BY
   a.Id,
   a.Name,
   a.Etc,

Basically I want to select from table tA and also check whether the entry in tA is linked or not to data in table tC. The linkage between the two tables is complex:

  • tA has a many to many relationship to tB (using table tAB)
  • tB has a one to many relationship with the table tC using the Foreign Key tB.cId
  • tC has a Foreign Key tc.dId to another table tD

Using the Entity Framework Code First I can’t use Include as it does not allow filtering but I can use projection so I get a functionally correct query using:

var query = from a in db.As
            where a.Id == 'y'
            select new
            {
               a,
               IsLinked = a.Bs
                           .Select(b => b.Cs)
                           .Select(c => c.Where(n => n.dId == 'x'))
                           .Select(h => h.Count()).Max() > 0
             };

The SQL generated is complex and slow, but works. I’m struggling to achieve the same functionality in nHibernate starting from a QueryOver:

var query = session.QueryOver<A>().Where(a => a.Id == 'y');

How do I create an equivalent projection that works across the multiple / nested join types (one being an OUTER join) without resorting to HQL? Or am I best off (since performance is likely to be poor) either:

  • Making two queries (one that retrieves the data and one that establishes the linkage)
  • Introducing views that encapsulate the complexity of the joins

Thanks

  • 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-27T01:41:52+00:00Added an answer on May 27, 2026 at 1:41 am

    this query should be equivalent, can you try it?

    var query = from a in db.As
            where a.Id == 'y'
            select new
            {
               a,
               IsLinked = a.Bs.SelectMany(b => b.Cs).Any(c => c.dId == 'x')
               // or
               IsLinked = a.Bs.Any(b => b.Cs.Any(c => c.dId == 'x'))
             };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im currently looking at migrating from fluent nHibernate to ADO.Net Entity Framework 4. I
I am looking into migrate a large project to Entity Framework 4.0 but am
How would you test this scenario? I've just started looking into NHibernate and having
I'm looking for patterns and principles for using with WPF and NHibernate in model-view-controller
I'm looking for a way to map a simple insert stored procedure using NHibernate
Our organization is looking to standardize on Entity Framework once v4 comes out. As
It seems that when using the following NHibernate query, I do not get a
Ok so I 'm just getting into nhibernate (using fluent). One thing that I
We are looking into using an ORM and I wanted some opinions/comparisons The basic
I've just started with the Play Framework and I'm running into some problems using

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.