NHibernate How do I query against an IList property?

后端 未结 6 773
死守一世寂寞
死守一世寂寞 2020-11-29 10:37

I am trying to query against an IList property on one of my domain classes using NHibernate. Here is a simple example to demonstrate:

public cl         


        
6条回答
  •  心在旅途
    2020-11-29 10:59

    As documented here:

    17.1.4.1. Alias and property references

    we can use:

    ...
    A collection key             {[aliasname].key}      ORGID as {coll.key}
    The id of an collection      {[aliasname].id}       EMPID as {coll.id}
    The element of an collection {[aliasname].element}  XID as {coll.element}
    ...
    

    there is a small bug in doc... instead of ".element" we have to use ".elements"

    var demos = this.session.CreateCriteria()
            .CreateAlias("Tags", "t")
    
            // instead of this
            // .Add(Restrictions.Eq("t", "a"))
    
            // we can use the .elements keyword
            .Add(Restrictions.Eq("t.elements", "a"))
    
            .List();
    

提交回复
热议问题