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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:59:02+00:00 2026-05-24T03:59:02+00:00

I am working on a legacy database which is quite intricate. The table customers

  • 0

I am working on a legacy database which is quite intricate.
The table customers is shared with the suppliers and who created this structure used a flag to identify the customers.
Since I am only interested in working with records defined as customers I’ve added a where clause to my mapping:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MyAssembly" namespace="MyAssembly.Domain">
    <class name="Customer" table="ANSADID" mutable="false" where="ANFCLI = 'Y'">
    <composite-id>
      <key-property name="CustomerCode" column="ANCOCO" type="String" length="10"></key-property>
      <key-property name="Company" column="ANCOSO" type ="String" length="5"></key-property>
    </composite-id>
    <property name="Name" column="ANINCO" type="String" length="100"></property>
  </class>
</hibernate-mapping>

As you can see I’ve pre-filtered all my customers with this clause: ANFCLI = 'Y'
Everything works perfectly fine if I query customers (the where clause is used):

var customers = session.QueryOver<Domain.Customer>()
    .Where(t => t.Company == "ABC01")
    .List();

But if I query the orders table – where I’ve got a many-to-one association:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MyAssembly" namespace="MyAssembly.Domain">
  <class name="Order" table="OCSAORH" mutable="false" where="OCHAMND = 0">
    <composite-id>
      <key-property name="Number" column="OCHORDN" type="String" length="10"></key-property>
      <key-property name="Ver" column="OCHAMND" type="Int32"></key-property>
      <key-property name="Company" column="OCHCOSC" type="String" length="5"></key-property>
    </composite-id>

   <many-to-one name="Customer" class="Customer" lazy="proxy" fetch="join">
      <column name="OCHCLII" not-null="true"/>
      <column name="OCHCOSC" not-null="true"/>
    </many-to-one>
  </class>
</hibernate-mapping>

the filter on the entity customers is lost.
I was reading somewhere that the where clause doesn’t work on a association and you have to use a where clause on the collection (bag, set, etc etc) but, how can I do that with a many-to-one?

Thanks for you help.

  • 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-24T03:59:02+00:00Added an answer on May 24, 2026 at 3:59 am

    What about mapping Customer using a discriminator using ANFCLI and then setting the discriminator value to ‘Y’. I think NHibernate will treat this a little more rigourously than a where clause.

    <class name="Customer" table="ANSADID" mutable="false" discriminator-value="Y">
      <composite-id>
        <key-property name="CustomerCode" column="ANCOCO" type="String" length="10" />
        <key-property name="Company" column="ANCOSO" type ="String" length="5" />
      </composite-id>
      <discriminator column="ANFCLI" />
      <property name="Name" column="ANINCO" type="String" length="100" />
    </class>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with a legacy SQL Server database which has a core table with
I am working with a database from a legacy app which stores 24 floating
I'm working on a legacy database table that has a phone no. field but
I've been working with a Legacy application which interacts with a database through ADODB,
I am working with a legacy database that has a table to store up
I'm working with a legacy database which doesn't use great conventions, but I'm unable
Im working on a legacy database, that cant be changed. I have a table
I have a small database which is legacy from an almost defunct project. This
I'm working on a WPF system which hooks onto an old legacy database using
I'm working with a legacy database which due to poor management and design has

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.