Fluent Nhibernate子类将HasMany与where子句映射到Parent Class中的列

时间:2014-09-18 07:58:36

标签: c# fluent-nhibernate mapping where-clause has-many

我有三个实体类:实体,特殊和常规,层次结构如下

public class Entity
{
    public Guid Id { get; set; }
    public bool IsDeleted { get; set; }
}

public class Special : Entity
{
    public IEnumerable<Regular> Regulars { get; set; }
}

public class Regular : Entity
{

}

要映射此实体,我使用ClassMap和SubclassMap 在我的子类中,我尝试将来自实体Special的集合Regulars映射到Where子句,如下所示:

public class SpecialMap : SubclassMap<Special>
{
    public SpecialMap()
    {
        HasMany(x => x.Regulars).Where("IsDeleted = 0");
    }
}

但它不起作用,因为当我尝试使用此集合时,会显示错误无效的列名称'IsDeleted'。似乎nhibernate试图在表Regular中找到IsDeleted列,但是在表Entity中没有这样的列。我该怎么办?

PS。可能我说的不正确,这是我的英语水平:) 这与我的问题NHibernate explicit fluent column mapping完全相同,但没有有用的答案

1 个答案:

答案 0 :(得分:0)

public class RegularMap : SubclassMap<Regular>
{
    public RegularMap()
    {
        Table("Regular")
        References(x => x.Special,"SpecialID");
    }
}

public class SpecialMap : SubclassMap<Special>
{
    public SpecialMap()
    {
        HasMany(x => x.Regulars).KeyColumn("SpecialID").Where("IsDeleted = 0");
    }
}