views:

11

answers:

1

Hi,

I have the following two tables:

Package
id

ClientPackage
id
clientNumber
packageId

The thing is that I do not have a Client table in this database (it resides in another database). Is there a way that I can create a Client mapping to a Client model which just consist of distinct "clientNumber" from the ClientPackage table while treating ClientPackage as a association table -- meaning that I do not want a class or mapping for ClientPackage. I'm thinking that I could use a component and an idbag to accomplish this but I just wanted a more experienced opinion so that I know I'm doing the right thing.

+1  A: 

From NH's perspective, this is not a many-to-many relationship, precisely because Client is not mapped.

The mapping depends on how you want it represented in the domain model.

An idbag would work fine for mapping Package.Clients as an ICollection<int>. You don't need a component:

<idbag name="Clients" table="ClientPackage">
  <collection-id column="id" type="...">
    <generator class="..."/>
  </collection-id>
  <key column="packageId"/>
  <element column="clientNumber"/>
</idbag>

And then you'll use those ids to get the clients in the other database.

Diego Mijelshon