为什么 NHibernate 不能访问从抽象基类继承的属性。当我尝试QueryOver
在Where
子句中使用属性时,我得到
无法解析属性:ID:TheWorkshop.Web.Models.Customer
var customer = Session.QueryOver<Customer>()
.Where(c=>c.ID ==id)
.SingleOrDefault<Customer>();
Intelisense 帮助我构建查询并编译解决方案,因此类上有一个ID
属性Customer
。Customer的ID
属性继承自抽象Contact
类,抽象类又继承自DomainEntity<T>
暴露受保护字段的 a。
public abstract class DomainEntity<T>
{
protected Guid _persistenceId;
//...
}
public abstract class Contact : DomainEntity<Contact>
{
public virtual Guid ID
{
get { return _persistenceId; }
}
public virtual Address Address
{
get { return _address; }
set { _address = value; }
}
//...
}
并在映射文件中
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="TheWorkshop.Web"
namespace="TheWorkshop.Web.Models"
default-access="field.camelcase-underscore"
default-lazy="true">
<class name="Contact" table="Contacts" abstract="true">
<id name="_persistenceId" column="ID" type="Guid" access="field"
unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid.comb" />
</id>
<!-- ... -->
<union-subclass name="Customer" table="Customers">
在回答了一个类似问题后,我更新为NHibernate 3.3.3-CR1
fromNHibernate 3.3.2.4000
但我仍然遇到同样的问题。