Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate query against the key field of a dictionary (map)
    primarykey
    data
    text
    <p>I have an object model where a Calendar object has an <code>IDictionary&lt;MembershipUser, Perms&gt;</code> called UserPermissions, where MembershipUser is an object, and Perms is a simple enumeration. This is in the mapping file for Calendar as</p> <pre><code>&lt;map name="UserPermissions" table="CalendarUserPermissions" lazy="true" cascade="all"&gt; &lt;key column="CalendarID"/&gt; &lt;index-many-to-many class="MembershipUser" column="UserGUID" /&gt; &lt;element column="Permissions" type="CalendarPermission" not-null="true" /&gt; &lt;/map&gt; </code></pre> <p>Now I want to execute a query to find all calendars for which a given user has some permission defined. The permission is irrelevant; I just want a list of the calendars where a given user is present as a key in the UserPermissions dictionary. I have the username property, not a <code>MembershipUser</code> object. How do I build that using QBC (or HQL)? Here's what I've tried:</p> <pre><code>ISession session = SessionManager.CurrentSession; ICriteria calCrit = session.CreateCriteria&lt;Calendar&gt;(); ICriteria userCrit = calCrit.CreateCriteria("UserPermissions.indices"); userCrit.Add(Expression.Eq("Username", username)); return calCrit.List&lt;Calendar&gt;(); </code></pre> <p>This constructed invalid SQL -- the WHERE clause contained <code>WHERE membership1_.Username = @p0</code> as expected, but the FROM clause didn't include the MemberhipUsers table.</p> <p>Also, I really had to struggle to learn about the <code>.indices</code> notation. I found it by digging through the NHibernate source code, and saw that there's also <code>.elements</code> and some other dotted notations. Where's a reference to the allowed syntax of an association path? I feel like what's above is very close, and just missing something simple.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload