I am learning to use fluent nhibernate and am having trouble understanding how to create my mappings. I have a table that has a multi-column primary key, but I can't get it to map correctly. I have the following fluent mapping -
public class MyEntityMappingOverride : IAutoMappingOverride<MyEntity>
{
public void Override(AutoMapping<MyEntity> mapping)
{
mapping.CompositeId()
.KeyProperty(x => x.Id_1, "Id_1")
.KeyProperty(x => x.Id_2, "Id_2");
mapping.References(x => x.otherEntity)
.Column("JoinColumn");
// Commented out to attempt to map to another entity on multiple columns
//mapping.HasMany(x => x.thirdEntit)
// .KeyColumns.Add("thirdId_1", "thirdId_2")
// .Cascade.All();
}
}
The problem that I am having is the composite id doesn't seem to be working.
Here is a snippet from the produced mapping file -
<id name="Id" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="identity" />
</id>
I then get an error that column (id) is not found in any table in the query.
Am I wrong in thinking that my mapping code will produce the correct composite ID? Am I missing something or doing something incorrectly?
AutoMap...UseOverridesFromAssemblyOf<MyEntityMappingOverride>()
– Vadim