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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:08:38+00:00 2026-06-11T15:08:38+00:00

I’m using Fluent-Nhibernate version 1.3 and I’m trying to make a query envolving 5

  • 0

I’m using Fluent-Nhibernate version 1.3 and I’m trying to make a query envolving 5 tables. I created a sql query for an oracle database and I’m trying to replicate with linq-to-nhibernate.

Following a sample of my entities and mapping.

Entities:

public class A
{
    public virtual int idA { get; set; }
    public virtual String codA { get; set; }
    public virtual String tipoA { get; set; }
    public virtual IList<B> listB { get; set; }
}

public class B
{
    public virtual C objectC { get; set; }
    public virtual A objectA { get; set; }
    public virtual DateTime dtBegin { get; set; }
    public virtual DateTime dtEnd { get; set; }
}

public class C
{
    public virtual int idC { get; set; }
    public virtual String codeC { get; set; }
    public virtual IList<B> listB { get; set; }
    public virtual IList<D> listD { get; set; }
}

public class D
{
    public virtual C objectC { get; set; }
    public virtual string flgD { get; set; }
    public virtual DateTime dtBegin { get; set; }
    public virtual DateTime dtEnd { get; set; }
    public virtual E objectE { get; set; }
}

public class E
{
    public virtual int idE { get; set; }
    public virtual String dsE { get; set; }
    public virtual DateTime dtBegin { get; set; }
    public virtual DateTime dtEnd { get; set; }
    public virtual IList<D> listD { get; set; }
}

My mapping:

class AMap : ClassMap<A>
{
    public AMap()
    {
        Table("A");

        Id(x => x.idA, "ID_A").GeneratedBy.Sequence("StringA");
        Map(x => x.tipoA, "TP_A");
        Map(x => x.codA, "CODE_A");
        HasMany(x => x.listB).Cascade.All().KeyColumn("ID_A");
    }
}

class BMap : ClassMap<B>
{
    public BMap()
    {
        Table("B");

        CompositeId()
            .KeyReference(x => x.objectC, "ID_C")
            .KeyReference(x => x.objectA, "ID_A")
            .KeyProperty(x => x.dtBegin, "DT_BEGIN");

        Map(x => x.dtEnd, "DT_END");
    }
}

class CMap : ClassMap<C>
{
    public CMap()
    {
        Table("C");
        Id(x => x.idC, "ID_C").GeneratedBy.Sequence("StringC");
        Map(x => x.codeC, "CODE_C");
        HasMany(x => x.listB).Cascade.All().KeyColumn("ID_C");
        HasMany(x => x.listD).Cascade.All().KeyColumn("ID_D");
    }
}

class DMap : ClassMap<D>
{
    public DMap()
    {
        Table("D");

        CompositeId()
            .KeyReference(x => x.objectC, "ID_C")
            .KeyProperty(x => x.flgD, "FLG_D")
            .KeyProperty(x => x.dtBegin, "DT_BEGIN");
        References(x => x.objectE, "CODE_E");
        Map(x => x.dtEnd, "DT_END");
    }      
}

class EMap : ClassMap<E>
{
    public EMap()
    {
        Table("E");

        Id(i => i.idE, "ID_E").GeneratedBy.Assigned();
        Map(m => m.dsE, "DSC_E");
        Map(m => m.dtBegin, "DT_BEGIN");
        Map(m => m.dtEnd, "DT_END");
        HasMany(x => x.listD).Cascade.All().KeyColumn("ID_E");
    }
}

My SQL Query(it works):

SELECT C.CODE_C, E.CODE_E, E.DT_BEGIN
FROM TABLEA A, TABLEB B, TABLEC C, TABLED D, TABLEE E
WHERE A.CODE_A = '0000' AND A.ID_A = B.ID_A AND B.ID_C = C.ID_C AND B.DT_END IS NULL
AND C.ID_C = D.ID_C AND D.DT_END IS NULL AND D.CODE_E = E.CODE_E AND E.DT_END IS NULL;

I tried to use multiple join but then some relathionship are collections so I would have to make a where inside the join.

So my question is: is possible to make this same Sql query as linq-to-nhibernate or is better to make a sequence of selects? And no i can’t change the database.

Thanks in advance.

  • 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-11T15:08:39+00:00Added an answer on June 11, 2026 at 3:08 pm

    the is null query is only possible using DateTime? as type

    var query = from b in B
                from c in b.C
                from d in c.listD
                from e in d.E
                where b.A.Code == "0000" && b.EndDate == null & ...
                select new { Ccode = c.Code, Ecode = e.Code, E_BeginDate = e.BeginDate }
    

    Update: to answer the third comment

    grouping the results has to be done in memory because grouping in sql can only return aggregations

    var results = query.AsEnumerable()
        .GroupBy(a => a.Ccode, a => a.Ecode, (key, values) => new { Ccode = Key, Ecodes = values.ToList() })
        .List();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.