Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# (N) 休眠从架构中查找内容:对象<;-属性值->;属性_C#_Java_Database_Nhibernate_Hibernate - Fatal编程技术网

C# (N) 休眠从架构中查找内容:对象<;-属性值->;属性

C# (N) 休眠从架构中查找内容:对象<;-属性值->;属性,c#,java,database,nhibernate,hibernate,C#,Java,Database,Nhibernate,Hibernate,我们有一个共同的数据库模式: 对象属性 假设我们谈论房子。房子可以有很多属性(门的形状、屋顶的颜色等)。混凝土房屋的属性数量未知 使用直接映射到对象: House-包含HouseAttributeValue对象的集合 HouseAttributeValue-包含属性对象及其字符串值 HouseAttribute-包含属性名称 现在,simple get按预期工作: ICriteria criteria = this.Repository.CreateCriteria(typeof(House

我们有一个共同的数据库模式:

对象属性

假设我们谈论房子。房子可以有很多属性(门的形状、屋顶的颜色等)。混凝土房屋的属性数量未知

使用直接映射到对象:

  • House-包含HouseAttributeValue对象的集合
  • HouseAttributeValue-包含属性对象及其字符串值
  • HouseAttribute-包含属性名称
现在,simple get按预期工作:

ICriteria criteria = this.Repository.CreateCriteria(typeof(House))
IList<House> searchResult = this.Repository.GetList<House>();

如何使用NHibernate(或Hibernate)实现这一点?希望看到代码中没有直接SQL语句的解决方案,但实际上欢迎任何解决方案。

也许您需要HQL示例查询(QBE)

假设这个简单的定义

class House
{
    public int Id{get;set;}
    .
    .
    .
    public IList<AttributeValue> AttributeValues {get;set;} 
}

class AttributeName
{
    public int Id{get;set;}
    .
    .
    .
    public string Name{get;set;}    
}

class AttributeValue
{
    public int Id{get;set;}
    .
    .
    .
    public House House {get;set;}
    public AttributeName Attribute{get;set;}
    public string Value {get;set;}
}
class House
{
    public int Id{get;set;}
    .
    .
    .
    public IList<AttributeValue> AttributeValues {get;set;} 
}

class AttributeName
{
    public int Id{get;set;}
    .
    .
    .
    public string Name{get;set;}    
}

class AttributeValue
{
    public int Id{get;set;}
    .
    .
    .
    public House House {get;set;}
    public AttributeName Attribute{get;set;}
    public string Value {get;set;}
}
ICriteria criteria = this.Repository.CreateCriteria(typeof(House))
criteria.CreateAlias("AttributeValues", "av");
criteria.SetFetchMode("av", FetchMode.Select);
criteria.Add(Expression.Eq("av.Attribute.Name", "door") && Expression.Eq("av.Value", "glass"));
criteria.Add(Expression.Eq("av.Attribute.Name", "window") && Expression.Eq("av.Value", "big"));
IList<House> houses = criteria.List<House>();
criteria.SetFetchMode("AttributeValues", FetchMode.Select);