How to query collections in NHibernate

Posted by user305813 on Stack Overflow See other posts from Stack Overflow or by user305813
Published on 2010-03-31T08:51:36Z Indexed on 2010/03/31 8:53 UTC
Read the original article Hit count: 379

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about map