views:

60

answers:

1

Hi, I have a class:

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

and a mapping file:

<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>

So now I can add many attributes and values to a User. How can I query those attributes so I can get ie. Get all the users where attributename is "Age" and attribute value is "20" ? I don't want to do this in foreach because I may have millions of users each having its unique attributes.

Please help

A: 

You can do it using HQL.

For example:

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