I am using the joined-subclass mapping and all works fine with one exception. If I delete the subclass I want to hold the data from the basic class but this entry will be deleted too. Is there a possibility to prevent it? Here is what I use in code at the moment:
Code:
public class DetailInfo
{
private Guid _id = Guid.Empty;
private string _title = String.Empty;
public virtual Guid Id
{
get { return _id; }
set { _id = value; }
}
public virtual string Title
{
get { return _title; }
set { _title = value; }
}
}
public class MoreDetailInfo : DetailInfo
{
private string _subtitle = String.Empty;
public virtual string Subtitle
{
get { return _subtitle; }
set { _subtitle = value; }
}
}
The mapping file looks like this:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="MyNamespace" assembly="MyAssemblyName">
<class name="DetailInfo" table="Details" >
<id name="Id" column="id" type="System.Guid">
<generator class="guid" />
</id>
<property name="Title" type="string" />
<joined-subclass name="MoreDetailInfo" table="MoreDetails" lazy="false" proxy="MoreDetailInfo">
<key column="detailId" />
<property name="Subtitle" type="string" />
</joined-subclass>
</class>
</hibernate-mapping>
And inside of the database I have two tables named Details and MoreDetails.
Code:
CREATE TABLE [dbo].[Details](
[id] [uniqueidentifier] NOT NULL,
[title] [nvarchar](50) COLLATE Latin1_General_CI_AS NOT NULL,
CONSTRAINT [PK_Details] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[MoreDetails](
[detailId] [uniqueidentifier] NOT NULL,
[subtitle] [nvarchar](50) COLLATE Latin1_General_CI_AS NOT NULL,
CONSTRAINT [PK_MoreDetails] PRIMARY KEY CLUSTERED
(
[detailId] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[MoreDetails] WITH CHECK ADD CONSTRAINT [FK_MoreDetails_Details1] FOREIGN KEY([detailId])
REFERENCES [dbo].[Details] ([id])
GO
ALTER TABLE [dbo].[ProofSelections] CHECK CONSTRAINT [FK_MoreDetails_Details1]
What I want is when I delete a MoreDetail object the entry from the MoreDetails table will be deleted but the entry in the Details table should be still stored. Is this possible? At the moment if I delete a MoreDetail object the entry from the MoreDetail table will deleted but from the Details table too.
Any suggestions?