【问题标题】:Fluent Nhibernate sublass mapping HasMany with where clause with column from Parent ClassFluent Nhibernate sublass 映射 HasMany 与 where 子句与父类中的列
【发布时间】:2014-11-12 11:21:31
【问题描述】:

我有三个实体类:Entity、Special 和 Regular,其层次结构如下

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 在我的子类中,我尝试使用 Where 子句从实体 Special 映射集合 Regulars,如下所示:

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

但它不起作用,因为当我尝试使用此集合时,会显示错误 Invalid column name 'IsDeleted'。似乎 nhibernate 试图在表 Regular 中找到 IsDeleted 列,但只有在表 Entity 中没有这样的列。我能用它做什么?

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

【问题讨论】:

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


    【解决方案1】:
    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");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-04-03
      • 2012-10-19
      • 1970-01-01
      • 1970-01-01
      • 2011-10-03
      • 2011-12-20
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多