2010-03-31 19 views
0

我有一個類:如何查詢館藏NHibernate的

public class User 
{ 
    public virtual int Id { get; set; } 
    public virtual string Name { get; set; } 
    public virtual IDictionary<string, string> Attributes { get; set; } 
} 

和映射文件:

<class name="User" table="Users"> 
    <id name="Id"> 
     <generator class="hilo"/> 
    </id> 
    <property name="Name"/> 

    <map name="Attributes" table="UserAttributes"> 
     <key column="UserId"/> 
     <index column="AttributeName" type="System.String"/> 
     <element column="Attributevalue" type="System.String"/> 
    </map> 
</class> 

所以,現在我可以在許多屬性和值添加到用戶。 我怎樣才能查詢這些屬性,所以我可以得到ie。 獲取attributename爲「Age」且屬性值爲「20」的所有用戶? 我不想在foreach中這樣做,因爲我可能有數百萬用戶,每個用戶都有其獨特的屬性。

請幫忙

回答

0

您可以使用HQL來做到這一點。

例如:

from User u join u.Attributes attr 
where index(attr) = 'Age' and attr = '20'