我有下表
tblChild
父代号子号名称
FatherCode
并且ChildNumber
是表的主键。
由于在这个数据库中经常发生这样的事情(我对它有零控制),我为我创建了以下类来映射 Id:
public class ComposedId {
public virtual int FatherId {get;set;}
public virtual int ChildId {get;set;}
//More code implementing Equals and GetHashCode
}
现在,映射是这样的:
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"));
}));
但是当我尝试查询表时,NHibernate 会尝试将 Id 作为列获取。
我不知道我做错了什么,我尝试了很多方法来用这种结构映射它,但没有任何效果:(