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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:58:14+00:00 2026-05-24T11:58:14+00:00

I have these entities in my database For a given Job , I want

  • 0

I have these entities in my database

enter image description here

For a given Job, I want to basically get the results in the following form

<Translation>,<ExternalUnit.Text>,<ExternalTranslation.Text>

where the joining condition is that Translation.Unit.Text == ExternalUnit.Text

This is what I have so far, working fine:

var props = session.QueryOver<Translation>(() => translation)
            .Select(c => translation.Id, c => externalUnit.Text, c => externalTranslation.Text)
            .JoinAlias(() => translation.TranslationUnit, () => unit)                
            .JoinAlias(() => unit.Job, () => job)
            .Where(() => unit.Job == job)
            .JoinAlias(() => job.ExternalUnits, () => externalUnit)
            .JoinAlias(() => externalUnit.ExternalTranslations, () => externalTranslation)
            .Where(() => externalUnit.Text == unit.Text)
            .List<object[]>();

var translations = session.QueryOver<Translation>(() => translation)                
            .JoinAlias(() => translation.TranslationUnit, () => unit)                
            .JoinAlias(() => unit.Job, () => job)
            .Where(() => unit.Job == job)
            .JoinAlias(() => job.ExternalUnits, () => externalUnit)
            .JoinAlias(() => externalUnit.ExternalTranslations, () => externalTranslation)
            .Where(() => externalUnit.Text == unit.Text)
            .List<Translation>()
            .ToList();

Then I loop through translations, referring to props. However, I don’t like this approach since I unnecessarily perform two (almost identical) queries to the database instead of just one.

But I can’t get the desired projection working. I was thinking about something like this:

var data = session.QueryOver<Translation>(() => translationAlias)                
            .JoinAlias(() => translation.TranslationUnit, () => unit)                
            .JoinAlias(() => unit.Job, () => job)
            .Where(() => unit.Job == job)
            .JoinAlias(() => job.ExternalUnits, () => externalUnit)
            .JoinAlias(() => externalUnit.ExternalTranslations, () => externalTranslation)
            .Where(() => externalUnit.Text == unit.Text)
            .Select(() => translation, () => externalUnit.Text, () => externalTranslation.Text)
            .List()

but, obviously, NHibernate does not like the Select(() => translation...) bit (it does not allow me to project the whole entity).

Ideally I would like to select into anonymous types, like

var data = session.QueryOver<Translation>()
             ...
             .Select(() => new { A = translation, B = externalTranslation })

but I guess NHibernate is not there so far…

Thank you very much for any suggestion.

  • 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-24T11:58:15+00:00Added an answer on May 24, 2026 at 11:58 am

    I’ve got it! NHibernate’s LINQ provider saved me. What’s great about it is that it can select into anonymous types, which makes joining so much easier. Just in case someone is curious, here it is for my particular case:

    var q = 
    (from c in
      (from b in            
        (from translation in session.Query<Translation>()
         join unit in units on translation.Unit equals unit
         where unit.Job == job
         select new { Translation = translation, Original = unit.Text })         
       join extUnit in externalUnits on job equals extUnit.Job
       where extUnit.Text == b.Original
       select new { Translation = b.Translation, ExternalUnit = extUnit })
     join extTranslation in extTranslations on c.ExternalUnit equals extTranslation.Unit
     select new { Translation = c.Translation, Suggestion = extTranslation })
     .ToList();
    

    The SQL it generates is very reasonable, so I am pretty happy 🙂

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

Sidebar

Related Questions

I have my domain entities. These entities are all together in a class library.
I have a table in my database that represents datafields in a custom form.
If I have the following set of entities: A --> (unowned) B \ -->
I have a database with two entities, A and B. A and B have
So I've got some data. There are entities. Entities have an arbitrary number of
I have container of geometrical entities. Let's assume there is circle, ellipse, line, arc.
I have 2 Entities, related by a many-to-many relationship. Thing<<->>Tag There is one NSArrayController
I have entity e.g. Product which aggregates other entities such as Category . Those
I have these 3 tables: and I'm using this code to join them together
I have these three lists with the same number of elements List<String>competitoinsIDs = new

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.