Je travaille avec 2 tables, les employés et une table appelée EmployeeGroups comme suit. J'ai omis la plupart des colonnes non pertinentes ci-dessous. Je me bats pour cartographier la relation de clé étrangère. C'est une relation un-à-un où tous les EmployeeId de la table Employés n'existeront pas dans la table EmployeeGroups. Je me demande comment configurer la relation EmployeeId dans mes fichiers de mapping ci-dessous?Difficulté pour mapper une relation avec NHibernate
employés
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])
Mes employés de fichier de mappage jusqu'à présent
<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>
Mon EmployeeGroups fichier de mappage si semble beaucoup comme celui-ci
<?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>