Hi,
I run into a problem when trying to load an parent object and its children.
My parent class Has a assigned PK and an Identity column.
I have a unique constaint on the Identity.
The children has the Identity column of the father as FK.
The load did not bring the children.
When i changed the PK of the Parent to the Identity it brought all the children but i cant change my schema.
I am attaching the code:
DB schema:
CREATE TABLE [dbo].[XXXParent](
[mPIdentity] [int] IDENTITY(1,1) NOT NULL,[PID] [int] NOT NULL,
CONSTRAINT [PK_XXXParent] PRIMARY KEY CLUSTERED
([PID] ASC)) ON [PRIMARY]
CREATE TABLE [dbo].[XXXChild](
[mPIdentity] [int] NOT NULL,[CID] [int] NOT NULL,
CONSTRAINT [PK_XXXChild] PRIMARY KEY CLUSTERED
([mPIdentity] ASC,[CID] ASC)) ON [PRIMARY]
ALTER TABLE [dbo].[XXXChild] WITH CHECK ADD CONSTRAINT [FK_XXXChild_XXXParent] FOREIGN KEY([mPIdentity])
REFERENCES [dbo].[XXXParent] ([mPIdentity])
ALTER TABLE [dbo].[XXXChild] CHECK CONSTRAINT [FK_XXXChild_XXXParent]
Mapping(parent):
<class name="Root" table="XXXParent">
<id name="PID">
<generator class="assigned" />
</id>
<property name="PIdentity" column="mPIdentity" update="false" insert="false"/>
<bag name="Leafs" cascade="all" optimistic-lock="false" inverse="true" lazy="false" table="XXXChild">
<key>
<column name="mPIdentity"/>
</key>
<one-to-many class="Leaf"/>
</bag>
</class>
Mapping(child):
Thx,
Tomer
|