Mapping file for Employee:
Code:
<class name="BitConstruct.PatientManager.Model.Entities.Employee, BitConstruct.PatientManager.Model"
table="Employees">
<id name="Id" unsaved-value="0" access="nosetter.pascalcase-m-underscore" type="Int32"
column="EmployeeId">
<generator class="identity" />
</id>
<property name="Country" column="Country" />
<many-to-one name="Firm" column="Firm_FirmId" class="BitConstruct.PatientManager.Model.Entities.Firm, BitConstruct.PatientManager.Model"
not-null="true" outer-join="false" />
<many-to-one name="InsuranceCompany" column="InsuranceCompany_InsuranceCompanyId" class="BitConstruct.PatientManager.Model.Entities.InsuranceCompany, BitConstruct.PatientManager.Model"
not-null="true" outer-join="false" />
<many-to-one name="Job" column="Job_JobId" class="BitConstruct.PatientManager.Model.Entities.Job, BitConstruct.PatientManager.Model"
outer-join="false" />
<property name="Active" column="Active" type="Boolean" />
<property name="Title" column="Title" type="String" />
<property name="FirstName" column="FirstName" type="String" />
<property name="LastName" column="LastName" type="String" not-null="true" />
<property name="Birthday" column="Birthday" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
<property name="Sex" column="Sex" />
<property name="InsuranceNumber" column="InsuranceNumber" type="String" />
<property name="Street" column="Street" type="String" />
<property name="ZipCode" column="ZipCode" type="Int32" />
<property name="City" column="City" type="String" />
<property name="Telephone" column="Telephone" type="String" />
<property name="Fax" column="Fax" type="String" />
<property name="Mobile" column="Mobile" type="String" />
<property name="Email" column="Email" type="String" />
<bag name="Pollutions" table="Employees_Substances" lazy="true" access="nosetter.pascalcase-m-underscore">
<key column="EmployeeId" />
<many-to-many column="Pollutions_SubstanceId" class="BitConstruct.PatientManager.Model.Entities.Substance, BitConstruct.PatientManager.Model" />
</bag>
<bag name="Physicals" inverse="true" lazy="true" access="nosetter.pascalcase-m-underscore"
cascade="all">
<key column="Employee_EmployeeId" />
<one-to-many class="BitConstruct.PatientManager.Model.Entities.Physical, BitConstruct.PatientManager.Model" />
</bag>
<bag name="VaccinationPlan" table="Employees_Vaccines" lazy="true" access="nosetter.pascalcase-m-underscore">
<key column="EmployeeId" />
<many-to-many column="VaccinationPlan_VaccineId" class="BitConstruct.PatientManager.Model.Entities.Vaccine, BitConstruct.PatientManager.Model" />
</bag>
</class>
Mapping file for Physical:
Code:
<class name="BitConstruct.PatientManager.Model.Entities.Physical, BitConstruct.PatientManager.Model"
table="Physicals">
<id name="Id" unsaved-value="0" access="nosetter.pascalcase-m-underscore" type="Int32"
column="PhysicalId">
<generator class="identity" />
</id>
<many-to-one name="Doctor" column="Doctor_DoctorId" class="BitConstruct.PatientManager.Model.Entities.Doctor, BitConstruct.PatientManager.Model"
outer-join="false" />
<many-to-one name="Employee" column="Employee_EmployeeId" class="BitConstruct.PatientManager.Model.Entities.Employee, BitConstruct.PatientManager.Model"
not-null="true" outer-join="false" />
<property name="PhysicalDate" column="PhysicalDate" type="DateTime"
not-null="true" />
<property name="PhysicalState" column="PhysicalState" not-null="true" />
<many-to-one name="InformationHeader" column="InformationHeader_InformationHeaderId" class="BitConstruct.PatientManager.Model.Entities.InformationHeader, BitConstruct.PatientManager.Model"
outer-join="false" />
<many-to-one name="SalesHeader" column="SalesHeader_SalesHeaderId" class="BitConstruct.PatientManager.Model.Entities.SalesHeader, BitConstruct.PatientManager.Model"
outer-join="false" />
<property name="Comment" column="Comment" type="String" />
<property name="FirmAttestation" column="FirmAttestation" type="String" />
<property name="EmployeeAttestation" column="EmployeeAttestation" type="String" />
<property name="PhysicalResult" column="PhysicalResult" />
<property name="BodilyExamination" column="BodilyExamination" type="Boolean" />
<property name="BodilyComplaint" column="BodilyComplaint" type="Boolean" />
<bag name="PhysicalComments" table="Comments_Physicals" lazy="true" access="nosetter.pascalcase-m-underscore">
<key column="PhysicalId" />
<many-to-many column="PhysicalComments_CommentId" class="BitConstruct.PatientManager.Model.Entities.Comment, BitConstruct.PatientManager.Model" />
</bag>
<bag name="TestedParameters" inverse="true" lazy="true" access="nosetter.pascalcase-m-underscore"
cascade="all-delete-orphan">
<key column="Physical_PhysicalId" />
<one-to-many class="BitConstruct.PatientManager.Model.Entities.TestedParameter, BitConstruct.PatientManager.Model" />
</bag>
<bag name="TestedSubstances" inverse="true" lazy="true" access="nosetter.pascalcase-m-underscore"
cascade="all-delete-orphan">
<key column="Physical_PhysicalId" />
<one-to-many class="BitConstruct.PatientManager.Model.Entities.TestedSubstance, BitConstruct.PatientManager.Model" />
</bag>
<bag name="Vaccinations" inverse="true" lazy="true" access="nosetter.pascalcase-m-underscore"
cascade="all-delete-orphan">
<key column="Physical_PhysicalId" />
<one-to-many class="BitConstruct.PatientManager.Model.Entities.Vaccination, BitConstruct.PatientManager.Model" />
</bag>
</class>
Instantiate Code:
Code:
Physical newPhysical = new Physical();
After that a window pops up, where the user must enter the some fields, one of them is the Employee field. If selected and ok is pressed, then the save code starts. Which, I have again to say, works the first time completly fine, and the second time is the exception, but it is also correctly saved to the DB (with the correct Employee reference). I still think the problem is, that the first object is somehow corrupted because it forgot its references in the IdentityMap entityEntries.
Hope that helps, and thanks for all of your help.