I am trying to perform a simple table-per-subclass mapping, but I am receving an error when the mapping is being loaded.
Code:
[TypeLoadException: Could not load type Infosnap.Business.Page from assembly NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc.]
System.Type.GetType(String typeName, Boolean throwOnError) +0
NHibernate.Cfg.Binder.ClassForFullNameChecked(String fullName, String errorMessage) +61
[MappingException: persistent class Infosnap.Business.Page not found]
My base class is FormPart, shown here...
Code:
public class FormPart
{
private int _id;
private string _internalName;
private int _sequenceIndex;
private string _title;
private string _instructions;
private bool _visible;
public FormPart()
{
// Default constructor.
}
public int ID
{
get {return _id;}
set {_id = value;}
}
public string InternalName
{
get {return _internalName;}
set {_internalName = value;}
}
public int SequenceIndex
{
get {return _sequenceIndex;}
set {_sequenceIndex = value;}
}
public string Title
{
get {return _title;}
set {_title = value;}
}
public string Instructions
{
get {return _instructions;}
set {_instructions = value;}
}
public bool Visible
{
get {return _visible;}
set {_visible = value;}
}
}
My subclass is Page, shown here.
Code:
public class Page : FormPart
{
private Form _parentForm;
private IList _sections;
public Page() : base()
{
// Default constructor.
}
public Form ParentForm
{
get {return _parentForm;}
set {_parentForm = value;}
}
public IList Sections
{
get
{
if (_sections == null)
{
_sections = new ArrayList();
}
return _sections;
}
set
{
_sections = value;
}
}
public void AddSection(Section section)
{
if (section == null)
{
throw new ArgumentNullException("section", "This argument cannot be null.");
}
section.ParentPage = this;
this.Sections.Add(section);
}
public void RemoveSection(Section section)
{
if (section == null)
{
throw new ArgumentNullException("section", "This argument cannot be null.");
}
else
{
this.Sections.Remove(section);
section.ParentPage = null;
}
}
}
The mapping file for FormPart is...
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Infosnap.Business.FormPart, Infosnap.Business" table="FormParts">
<id name="ID" column="ID" type="Int32" unsaved-value="0">
<generator class="identity" />
</id>
<property name="InternalName" column="InternalName" type="String" length="25" />
<property name="SequenceIndex" column="SequenceIndex" type="Int32" />
<property name="Title" column="Title" type="String" length="25" />
<property name="Instructions" column="Instructions" type="String" length="2000" />
<property name="Visible" column="Visible" type="Boolean" />
<joined-subclass name="Infosnap.Business.Page" table="Pages">
<key column="PageID" />
</joined-subclass>
</class>
</hibernate-mapping>
Finally, the tables are shown here...
Code:
CREATE TABLE [FormParts] (
[ID] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL ,
[InternalName] [nvarchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[SequenceIndex] [int] NULL ,
[Title] [nvarchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Instructions] [nvarchar] (2000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Visible] [bit] NULL ,
CONSTRAINT [PK_FormParts] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [Pages] (
[PageID] [int] NOT NULL ,
[FormID] [int] NOT NULL ,
CONSTRAINT [PK_Pages] PRIMARY KEY CLUSTERED
(
[PageID]
) ON [PRIMARY]
) ON [PRIMARY]
GO
I am fairly new at using NHibernate, but even following the examples in a few books, I cannot get this to work.
Another question, when you use this strategy, does it mean that you do not have to have a mapping file for the subclasses?
I appreciate any help on this.
KEVIN