我有旧的遗留数据库,它们的表中有死链接。我有像这样在 nhibernate 中映射的类:
<class name="Visible" table="table_visible">
<composite-id>
<key-many-to-one column="object_id" name="ObjectA" />
<key-many-to-one column="sub_object_id" name="SubObject" />
</composite-id>
<property column="visible" name="VisibleRow" />
</class>
和:
public class Visible
{
public virtual ObjectAClass ObjectA { get; set; }
public virtual SubObjectClass SubObject { get; set; }
public virtual bool VisibleRow { get; set; }
public override bool Equals(object obj)
{
var other = ((Visible)obj);
return this.ObjectA.Equals(other.ObjectA) && this.SubObject.Equals(other.SubObject);
}
public override int GetHashCode()
{
return this.ObjectA.GetHashCode() + (this.SubObject != null? this.SubObject.GetHashCode(): 0);
}
}
现在,当数据库中的所有连接都正确时,一切正常,但是当我找到没有实体的 sub_object_id 时,nhibernate 会抛出错误
No row with the given identifier exists:[SubObject#123]
有没有办法映射复合键,以便在找不到它的子实体时,不会加载整个实体(如内部连接)?
NHibernate v2.0.50727