I have two classes that I’m trying to map in Loquacious Nhibernate.
The mapping is like the following
public class FooMap : ClassMapping<Foo>
{
Table("FooTableName");
ComposedId(compIDMapper =>
{
compIDMapper.Property(x => x.SomeInt, m => m.Column("SomeInt"));
compIDMapper.ManyToOne(x => x.SomeReference, m => m.Column("SomeReference"));
});
}
public class BarMap : ClassMapping<Bar>
{
Table("BarTableName");
Id(x => x.ID, m => m.Column("barID"));
ManyToOne(x => x.Foo, m => m.Columns( columnMapper =>
{
columnMapper.Name("SomeIntID"); //Both of these columns are in the BarTableName like they should be
columnMapper.Name("SomeReferenceID");
}));
}
But when the mappings are being built I get the following error:
Foreign key (FK554EAF2427B2CA28:BarTableName[SomeIntID])) must have same number of columns as the refe,renced primary key (FooTableName[SomeInt, SomeReference])
I’m not sure what I’m doing wrong, it looks like it should work, but I’ve been banging my head on this for awhile now and haven’t gotten anywhere. Any ideas on what I’m doing wrong?
Finally figured this out, posting this for anyone else who comes along.
My problem was misunderstanding the columns mapper. What it is supposed to be is the following:
This solved the issue. Should have noticed it when I looked at the function signature, but I completely missed it.