Reputation: 3634
Here is a simplified version of my database model. I have two tables: "Image", and "HostingProvider" which look like this:
[Image]
[HostingProvider]
Image HostingproviderId is a many-to-one foreign key relationship to the HostingProvider table. (Each image has one hosting provider).
Essentially I want to be able to have my Image class look like this:
[Image]
In NHibernate, how can I create a mapping file that will combine the base_url from the HostingProvider table, into the Image class?
Upvotes: 2
Views: 932
Reputation: 40981
What you're looking for is this:
http://ayende.com/Blog/archive/2007/04/24/Multi-Table-Entities-in-NHibernate.aspx
Here's a peek of what it looks like:
<class name="Person">
<id name="Id" column="person_id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="Name"/>
<property name="Sex"/>
<join table="address">
<key column="address_id"/>
<property name="Address"/>
<property name="Zip"/>
<property name="Country"/>
<property name="HomePhone"/>
<property name="BusinessPhone"/>
</join>
</class>
Upvotes: 2
Reputation: 65445
public class Image {
public virtual HostingProvider HostingProvider { get; set; } // NHibernate takes care of this
public virtual string BaseUrl { get { return HostingProvider.BaseUrl; } }
}
Upvotes: 0