I have the following table
tblChild
FatherCode ChildNumber Name
FatherCode
and ChildNumber
are the primary keys of the table.
Since something like this happens very often in this database (I have ZERO control over it), I created the following class for me to map the Id:
public class ComposedId {
public virtual int FatherId {get;set;}
public virtual int ChildId {get;set;}
//More code implementing Equals and GetHashCode
}
Now, the mapping goes like this:
aMapper.Class<Child>(aClassMapper => aClassMapper.ComposedId(aComposedIdMapper =>
{
aComposedIdMapper.Property(aChild => aChild.Id); //Id's implementation is: public virtual ComposedId Id {get;set;}
}));
aMapper.Class<Child>(aClassMapper => aClassMapper.ComponentAsId(aChild => aChild.Id, aComponentAsIdMapper =>
{
aComponentAsIdMapper.Property(aComposedId => aComposedId.FatherId, aPropertyMapper => aPropertyMapper.Column("FatherCode"));
aComponentAsIdMapper.Property(aComposedId => aComposedId.ChildId, aPropertyMapper => aPropertyMapper.Column("ChildNumber"));
}));
But when I'm try to query the table, NHibernate tries to get the Id as a column.
I don't know what I'm doing wrong, and I tried a lot of ways to map this with this structure, but nothing works :(