jchapman wrote:
ronunes wrote:
I have a problem.
3 tables:
Company (CompanyId, Name)
Service (ServiceId, Name)
Company_Service (CompanyId, ServiceId, HourPrice)
How do map this relationship?
The easiest way (not the only way) is to just make a third entity. So the Company may have a One-To-Many relationship with the CompanyService entity. You then could have a property and a Many-To-One relationship from CompanyService to Service.
I solved...
<class name="Company,..." table="Company">
<id name="Id" type="Int32" unsaved-value="0">
<column name="CompanyId" sql-type="int" not-null="true" unique="true" index="PK_Company"/>
<generator class="native" />
</id>
<property name="Name" type="String">
<column name="Name" length="50" sql-type="varchar" not-null="false"/>
</property>
<bag name="CompanyServices" table="Company_Service" lazy="false">
<key column="CompanyId"/>
<composite-element class="CompanyService, ..." >
<property name="HourPrice" type="Decimal">
<column name="HourPrice" sql-type="real" not-null="false"/>
</property>
<many-to-one name="Service" column="ServiceId" />
</composite-element>
</bag>