tags:

views:

211

answers:

1

I need to create a new Many-To-One relationship on my User entity which joins against another entity. The problem is the other entity has a compound key of which 1 field is a field in the User entity and the other is a field in another Many-To-One entity.

User.Key -> User.NewThing.Key

User.SubThing.Key -> User.NewThing.Key

Below is the invalid mapping file I am ideally wanting to use where JeanieUserTyped is my newthing and the ApplicationId is the key in question which comes from ShortCode.ApplicationId.

Question is how do I tell it to map the application part of the compound key?

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="JeanieMaster.Domain.Entities" assembly="JeanieMaster.Domain">
    <class name="JeanieUser" table="DBSVR1.Jeanie_Master.dbo.JeanieUser" select-before-update="false" optimistic-lock="none">
     <id name="Id" column="UserId" type="Int32">
      <generator class="identity"/>
     </id>

     <property name="Mobile" type="String"/>
     <property name="UniqueReoccurBillingRefId" type="String"/>
     <property name="DateJoined" type="DateTime"/>
     <property name="IsActive" type="Boolean"/>

     <many-to-one name="MobileNetwork" class="MobileNetwork" column="MobileNetworkId" />
     <many-to-one name="ShortCode" class="ShortCode" column="ShortCodeId" />
     <many-to-one name="MobileHandset" class="MobileHandset" column="HandsetId" />

     <many-to-one name="JeanieUserTyped" class="JeanieUserTyped">
      <column name="Mobile" />
      <column name="ApplicationId" />
     </many-to-one>

    </class>
</hibernate-mapping>
+1  A: 

Hi,

Can you give more details, sounds like you have 3 entities,

User SubThing NewThing

Where NewThing resolves a Many-to-Many with User and SubThing - am I close?

Maybe like this:

User         -<  SubThing
 |                   | 
 /\                  /\
        NewThing

I don't suppose the composite key stuff in nhibernate is relevant?

Chris Kimpton
I've added a more specific edntry to my question
tigermain