Hi,
I am having a problem when trying create a many to many mapping. Consider the following tables:
CREATE TABLE [dbo].[student]
(
[Id] INT IDENTITY (1, 1) NOT NULL,
[Name] NVARCHAR(255) NOT NULL,
-- Some other stuff...
)
CREATE TABLE [dbo].[Subject]
(
[Id] INT IDENTITY (1, 1) NOT NULL,
[Name] NVARCHAR (50) NOT NULL,
-- Some other stuff...
)
CREATE TABLE [dbo].[studentToSubject]
(
[studentId] INT NOT NULL,
[subjectId] INT NOT NULL,
)
The interesting part of my student mapping file looks like this:
<id name="Id" type="Int32">
<column name="Id" sql-type="int" not-null="true" unique="true"/>
<generator class="native" />
</id>
<property name="Name" not-null="true" />
<bag name="subjects" table="studentToSubject">
<key column="studentId"></key>
<many-to-many column="subjectId" class="subject" />
</bag>
I want to end up with a student with a collection of their subjects. However, I get an error:
NHibernate.MappingException: Could not determine type for: MyApp.Domain.Subject, MyApp.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=865c2d2b185d0c4b, for columns: NHibernate.Mapping.Column(studentId).
I have seen some examples of this type of mapping, but they differ in the fact that their Id columns have name that match the mapping table name, for example their Id column in the student table is called 'studentId'. I cannot do this (it has to be Id) but I think this is the cause of the problem.
Thanks