I'm mapping a legacy database with nhibernate and having some problems with mapping a realation.
The two classes look like this
public class Questionnaire
{
public int Id {get; set;}
public string FormCode {get; set;}
public IList<Question> Questions {get; set;}
}
public class Question
{
public int Id{get; set;}
public Questionnaire Questionnaire {get;set;}
public string QuestionText{get;set;}
}
to tables that are like this
Questionnaire Table
Id int
FormCode varchar(100)
Question Table
Id int
FormCode varchar(100)
QuestionText varchar(max)
The relationship between the two tables being the formcode column.
My current mapping is like this
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="QDesign.Core.Models" assembly="QDesign.Core">
<class name="Questionnaire" table="_questionnaire_list">
<id column="Id" name="Id">
<generator class="identity"/>
</id>
<property name="FormCode" column="FormCode"/>
<bag name="Questions" >
<key foreign-key="FormCode" property-ref="FormCode" />
<one-to-many class="Question" />
</bag>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="QDesign.Core.Models" assembly="QDesign.Core">
<class name="Question" table="_questionnaire_items">
<id column="ID" name="Id" unsaved-value="-1">
<generator class="identity" />
</id>
<property name="QuestionText" column="QuestionText" />
</class>
</hibernate-mapping>
When I run the mapping I get a Identifier type mismatch assuming it is trying to put the formcode into the Id of the question. Unfortunalty I am unable to change the structure of the table and I am at a lost at how to map this and any help would be greatly appriciated.
Colin G