Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate Criteria query building
    primarykey
    data
    text
    <p>I'm having some trouble understanding a bit of code. I've got 2 classes Company and CompanyLocation. Mapped as:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt; &lt;class name="Core.DataTransfer.CompanyLocation,Core.DataTransfer" table="`CompanyLocation`" lazy="true"&gt; &lt;id name="CompanyLocationId" column="`CompanyLocationID`" type="int"&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;many-to-one name="Company" cascade="none" column="`CompanyID`" not-null="true" /&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt; &lt;class name="Core.DataTransfer.Company,Core.DataTransfer" table="`Company`" lazy="true"&gt; &lt;id name="CompanyId" column="`CompanyID`" type="int"&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;property type="string" not-null="true" length="100" name="CompanyName" column="`CompanyName`" /&gt; &lt;bag name="CompanyLocations" inverse="true" lazy="true" cascade="all"&gt; &lt;key column="`CompanyID`" /&gt; &lt;one-to-many class="Core.DataTransfer.CompanyLocation,Core.DataTransfer" /&gt; &lt;/bag&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>I'm trying to query using a Criteria query as follows:</p> <pre><code> public IList&lt;CompanyLocation&gt; GetCompanyLocations(string sortExpression) { ICriteria criteria = _session.CreateCriteria(typeof(CompanyLocation)); if (!string.IsNullOrEmpty(sortExpression)) { Sort sort = new Sort(sortExpression); if (!string.IsNullOrEmpty(sort.AssociationPath)) { criteria.CreateCriteria(sort.AssociationPath).AddOrder(new Order(sort.SortColumn, sort.IsAscending)); } // if (!string.IsNullOrEmpty(sort.AssociationPath)) // { // criteria.CreateCriteria(sort.AssociationPath); // } // criteria.AddOrder(new Order(sort.SortColumn, sort.IsAscending)); } return criteria.List&lt;CompanyLocation&gt;(); } </code></pre> <p>When I call the method and pass in a sortExpression of "Company.CompanyName DESC" the Sort class will parse it so that: AssociationPath = "Company" SortColumn = "CompanyName" IsAscending = false</p> <p>The if block in the method that is not commented out works. If I change to the one that is commented out it fails with: could not resolve property: CompanyName </p> <p>I'm having trouble understanding why.</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.
    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