I'm working with 2 tables, Employees and a table called EmployeeGroups as follows. I've left out most of the unrelevant columns below. I'm struggling to map the foreign key relationship. Its a one-to-one relationship where not every EmployeeId in the Employees table will exist in the EmployeeGroups table. I'm wondering how to setup the EmployeeId relationship in my mapping files below?
Employees
CREATE TABLE [dbo].[Employees](
[EmployeeId] [int] IDENTITY(1,1) NOT NULL,
[ForeName] [nvarchar](20) COLLATE Latin1_General_CI_AI NOT NULL,
[SurName] [nvarchar](20) COLLATE Latin1_General_CI_AI NOT NULL,
CONSTRAINT [PK_Employees_1] PRIMARY KEY CLUSTERED
(
[EmployeeId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
EmployeeGroups
CREATE TABLE [dbo].[EmployeeGroups](
[GroupId] [int] NULL,
[EmployeeId] [int] NOT NULL,
[Active] [int] NULL,
CONSTRAINT [PK_EmployeeGroups] PRIMARY KEY CLUSTERED
(
[EmployeeId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
USE [DemoDEV]
GO
ALTER TABLE [dbo].[EmployeeGroups] WITH CHECK ADD CONSTRAINT
[FK_EmployeeGroups_Employees] FOREIGN KEY([EmployeeId])
REFERENCES [dbo].[Employees] ([EmployeeId])
My Employees mapping file so far
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="AdaptiveMaintenance.Core.Domain.Employee, AdaptiveMaintenance.Core" table="Employees" lazy="false">
<id name="ID" column="EmployeeId">
<generator class="assigned" />
</id>
<property name="Forename" column="ForeName" not-null="true"/>
<property name="Surname" column="SurName" not-null="true"/>
</class>
</hibernate-mapping>
My EmployeeGroups mapping file so far looks like this
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="AdaptiveMaintenance.Core.Domain.EmployeeGroup, AdaptiveMaintenance.Core" table="EmployeeGroups" lazy="false">
<id name="ID" column="EmployeeId">
<generator class="foreign" />
</id>
<property name="Active" column="Active" />
</class>