Deal all
First of all, look at the summary type definition:
public abstract class Person
{
public abstract Guid PersonID
{
get;
set;
}
public abstract string FirstName
{
get;
set;
}
public abstract string LastName
{
get;
set;
}
}
public class Customer:Person
{
#region override some properties of Person here
#endregion
public Guid CustomerID
{
get;
set;
}
public String Email
{
get;
set;
}
public ISet<Store> Stores
{
get;
set;
}
}
public class Store
{
public Guid StoreID
{
get;
set;
}
public String Name
{
get;
set;
}
public Customer Owner
{
get;
set;
}
}
Now, we do the mapping:
The Person with Customer:
<class name="HongXun.DAL.Model.Person, HongXunDataAccessLayer"
table="Person" abstract="true" >
<id name="PersonID" column="PersonID" type="Guid" length="36" >
<generator class="guid" />
</id>
<property name="FirstName" column="FistName" type="String" length="100" />
<property name="LastName" column="LastName" type="String" length="100" />
<!-- Customer-->
<joined-subclass table ="Customer" name="HongXun.DAL.Model.Customer,
HongXunDataAccessLayer" >
<key column="PersonID"/>
<property name="CustomerID" column="CustomerID" type="Guid" length="36"
update="false"/>
<property name="Email" column="Email" type="String" length="100" />
<!--
note: As the Customer type inherited from the Person type
when you insert a new Store in DB, The Person's ID value will inserted
into the Store table OwnerID column
so Store table foreign key constraint's primary key must be the
Person's ID column.
If the Store table foreign key constraint's primary key set to
Customer's primary key column, NH will be unable to
properly handle this mapping.
-->
<set name="Stores" table="Store" generic="true"
cascade="all-delete-orphan" >
<key column="OwnerID" foreign-key="FK_Store_Person" />
<one-to-many class="HongXun.DAL.Model.Store, HongXunDataAccessLayer"
/>
</set>
</joined-subclass>
</class>
The Store:
<class name="HongXun.DAL.Model.Store, HongXunDataAccessLayer" table="Store">
<id name="StoreID" column="StoreID" type="Guid" length="36" >
<generator class="guid" />
</id>
<many-to-one name="Owner" class="HongXun.DAL.Model.Customer"
column="OwnerID" />
<property name="Name" column="Name" type="String" length="100" />
</class>
--
江名峰(James.Jiang)
msn:[email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---