NHibernate version: 1.2 GA
Name and version of the database you are using: mssql2005
I can not think of any other way than to describe this database but as being normalized, but I can not for the life of me figure out how to map the following structure to my object.
Regarding the code below, it has been simplified immensely and I have typed most of it out by hand, I simply want to focus on the mapping of the BankCertified and Incorporated bools from the structure indicated below.
Any help is greatly appreciated.
Thanks,
Dave
Tables:
Code:
CREATE TABLE dbo.Agents(
Region char(2) NOT NULL,
State char(2) NOT NULL,
Code char(4) NOT NULL,
FirstName varchar(35) NOT NULL,
LastName varchar(40) NOT NULL,
PRIMARY KEY CLUSTERED (Region, State, Code)
)
GO
CREATE TABLE dbo.BankCertifiedAgents(
Region char(2) NOT NULL,
State char(2) NOT NULL,
Code char(4) NOT NULL,
PRIMARY KEY CLUSTERED (Region, State, Code)
)
GO
CREATE TABLE dbo.IncorporatedAgents(
Region char(2) NOT NULL,
State char(2) NOT NULL,
Code char(4) NOT NULL,
PRIMARY KEY CLUSTERED (Region, State, Code)
)
GO
ALTER TABLE dbo.BankCertifiedAgents ADD FOREIGN KEY(Region, State, Code) REFERENCES dbo.Agents (Region, State, Code)
GO
ALTER TABLE dbo.IncorporatedAgents ADD FOREIGN KEY(Region, State, Code) REFERENCES dbo.Agents (Region, State, Code)
GO
Classes:
Code:
public class Agent {
private Name _name;
private bool _bankCertified;
private bool _incorporated;
public virtual Name { get { return _name; } protected set { _name = value; } }
public virtual bool BankCertified { get { return _bankCertified; } protected set { _bankCertified = value; } }
public virtual bool Incorporated { get { return _incorporated; } protected set { _incorporated = value; } }
}
public class Id {
private string _region;
private string _state;
private string _code;
public virtual string Region { get { return _region; } protected set { _region = value; } }
public virtual string State { get { return _state; } protected set { _state = value; } }
public virtual string Code { get { return _code; } protected set { _code = value; } }
}
public class Name {
private string _first;
private string _last;
public virtual string First { get { return _first; } protected set { _first = value; } }
public virtual string Last { get { return _last; } protected set { _last = value } }
}
Mapping Document:
Code:
<class name="Agent" table="Agents" schema="dbo" mutable="false" lazy="true">
<composite-id class="Id">
<key-property name="Region"/>
<key-property name="State"/>
<key-property name="Code"/>
</composite-id>
<component name="Name" class="Name">
<property name="First" column="FirstName"/>
<property name="Last" column="LastName"/>
</component>
<!--- help -- BankCertified -->
<!--- help -- Incorporated -->
</class>