NHibernate Criteria query building -


I'm having some difficulty, which seems to be a little code I have 2 class company and company. As the map:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Hibernate-mapping xmlns = "vase: nehinet-mapping-20" & gt; & Lt; Class name = "Core.DataTransfer.CompanyLocation, Core.DataTransfer" table = "` Company Location '"Lazy =" True "& gt; & Lt; Id name = "CompanyLocationId" column = "` CompanyLocationID` "type =" int "& gt; & Lt; Generator class = "parent" /> & Lt; / Id & gt; & Lt; Many-to-one name = "company" cascade = "none" column = "` CompanyID` "no-null =" true "/> & Lt; / Square & gt; & Lt; / Hibernate-mapping & gt; & Lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Hibernate-mapping xmlns = "vase: nehinet-mapping-20" & 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 = "parent" /> & Lt; / Id & gt; & Lt; Property type = "string" no-null = "true" length = "100" name = "company name" column = "` company name` "/> & Lt; Bag name = "company location" inverted = "true" lazy = "true" cascade = "all" & gt; & Lt; Major column = "` company id` "/> & Lt; One-to-many classes = "core.data transfer.company location, core.data transfer" /> & Lt; / Bag & gt; & Lt; / Square & gt; & Lt; / Hibernate-mapping & gt;  

I am trying to query the following criteria by using a criteria query:

  public IList & lt; CompanyLocation & gt; GetCompanyLocations {String sort expression} {ICRTERIA criteria = _session.CreateCriteria (typef (company location)); If (! String.IsNullOrEmpty (sortExpression)) {sort sort = new sort (sort expression); If (! String.isnaloractai (sorted accessibility path)) {criteria. Create Seeratia (Sort Associate Path). Orders (New Order (Sort Solar Column, Sorting. ISACCING)); } // if (! String.IsNullOrEmpty (sort.AssociationPath)) // {// Criteria. Creatitritia (sort. Affiliation); //} // criteria.Adorder (new order (sorting class column, sorting .isccing)); } Return criteria. List & lt; Company Locations & gt; (); }  

When I call the method and pass in a kind of resolution of "Company.companyname DESC", the sort class will parse it on it so that: AssociationPath = "Company" SortColumn = "CompanyName" isAscending = false

If the comment has not been commented in the work, block if I change the comment on which it is commented then its failure: the asset is not resolved Can be done: CompanyName

I understand why the trouble is happening.

Most likely because CreateCriteria () creates a new benchmark (instead of modifying the original code) Expectation of your code)

ex> if (! String.IsNullOrEmpty (sort.AssociationPath)) {var criteria copyright = criteria. Creativity (sort.AssociationPath); } Criteria. Copy order order (new order (sort. Column, sorting.));

Or just plain

  if (! String.IsNullOrEmpty (sort.AssociationPath)) {criteria = criteria. Creatitirria (Sort ASSOCIATIVE PATH); } Criteria.ad order (new order (sort sort column, sort .asaking);  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -