NHibernate QueryOver is not a Linq provider (that is how to do join with QueryOver API)

Starting from NHibernate 3.0 a new API was build as a wrapper around the ICriteria object.

Obviously I’m talking about the powerful API called QueryOver. With this API you can build a wide range of query object, from the simplest to the more complicated one. But you need to remember that this API is not a Linq provider, and then you cannot apply those constructs typically applied in a Linq query. I explain with an example what I really mean.

Introduction: you have a data model with 2 table, Category and Customer, with a one-to-many relationship between them.

With Entity Framework and Linq To Entities it’s pretty simple to query data that belong to both entities, thanks to navigation properties and Linq provider, i.e. all customers that belong to a category with a specified Id, as shown in this example:


var customerList = customers.Where(c => c.CategoryId == 1);

If you try to execute the same query with the same where conditions applied to a QueryOverObject, like this example:


QueryOver<Customer>; qu = QueryOver.Of<Customer>()
      .Where(c => c.CategoryId == 1);

This code throws a NHibernateException saying that “could not resolve property: Category.Id of : MyNamespace.Customer”, suggesting to verify the mapping as property “Category.Id” could not be found”.

Obviously such a property doesn’t exist at all, it’s only the QueryOver API that concatenates the Navigation property and and its field named Id (in this example).

This means that: you cannot make a query with QueryOver API that refers to fields belonging to a navigation property in where clause….without explicitly defying a join between the object itself and its navigation property. An example will help to understand better.

Category cat = null;
QueryOver<Customer> query = QueryOver.Of<Customer>()
 .JoinAlias(x => x.Category, () =>; cat)
 .Where(x => cat.Id == 1);

I have defined a join with the JoinAlias method, which uses an alias (the Category object declared two rows before) to project the object under the navigation property. After that you can use this alias inside the others method (such as “Where” in this example) to refer to the navigation property field (cat.Id).

As you can see, the way you write the lambda expression inside a Linq provider’s where clause is quite different than the “”Where” condition of a QueryObject object.

Not even the logical operator “And” can be used in the same way. To apply this logical operator to the “where” filter you have to use the “And” method, as shown here:

Category cat = null;
QueryOver<Customer> query = QueryOver.Of<Customer>()
   .JoinAlias(x => x.Category, () => cat)
   .Where(x => cat.Id == 1)
   .And(x => cat.IsEnabled);

532 thoughts on “NHibernate QueryOver is not a Linq provider (that is how to do join with QueryOver API)

  1. Pingback: viagra canada
  2. Pingback: canada pharmacy
  3. Pingback: mazhor4sezon
  4. Pingback: canadian drugs
  5. Pingback: filmfilmfilmes
  6. Pingback: viagra canada
  7. Pingback: gRh9UPV
  8. Pingback: canada rx
  9. Pingback: 9-05-2022
  10. Pingback: kinoteatrzarya.ru
  11. Pingback: TopGun2022
  12. Pingback: Xvideos
  13. Pingback: XVIDEOSCOM Videos
  14. Pingback: drugstore online
  15. Pingback: northwestpharmacy
  16. Pingback: ivanesva
  17. Pingback: Northwest Pharmacy
  18. Pingback: buy viagra 25mg
  19. Pingback: dkyubn.bizwebs.com
  20. Pingback: canadian pharmacys
  21. Pingback: canadian viagra
  22. Pingback: Netflix
  23. Pingback: FILM
  24. Pingback: designchita.ru
  25. Pingback: YA-krasneyu
  26. Pingback: design-human.ru
  27. Pingback: designmsu.ru
  28. Pingback: vkl-design.ru
  29. Pingback: irida-design.ru
  30. Pingback: projectio
  31. Pingback: psy online
  32. Pingback: canadian drugstore
  33. Pingback: uels ukrain
  34. Pingback: Northwest Pharmacy
  35. Pingback: kwersv.proweb.cz
  36. Pingback: canada pharmacies
  37. Pingback: DPTPtNqS
  38. Pingback: qQ8KZZE6
  39. Pingback: D6tuzANh
  40. Pingback: SHKALA TONOV
  41. Pingback: chelovek-iz-90-h
  42. Pingback: 3Hk12Bl
  43. Pingback: 3NOZC44
  44. Pingback: 01211
  45. Pingback: tor-lyubov-i-grom
  46. Pingback: film-tor-2022
  47. Pingback: hd-tor-2022
  48. Pingback: hdorg2.ru
  49. Pingback: JXNhGmmt
  50. Pingback: Psikholog
  51. Pingback: netstate.ru
  52. Pingback: Link
  53. Pingback: psy
  54. Pingback: bit.ly
  55. Pingback: cleantalkorg2.ru
  56. Pingback: bucha killings
  57. Pingback: War in Ukraine
  58. Pingback: Ukraine
  59. Pingback: site
  60. Pingback: stats
  61. Pingback: Ukraine-war
  62. Pingback: movies
  63. Pingback: gidonline
  64. Pingback: web
  65. Pingback: film.8filmov.ru
  66. Pingback: video
  67. Pingback: filmgoda.ru
  68. Pingback: rodnoe-kino-ru
  69. Pingback: stat.netstate.ru
  70. Pingback: sY5am
  71. Pingback: Dom drakona
  72. Pingback: JGXldbkj
  73. Pingback: aOuSjapt
  74. Pingback: ìûøëåíèå
  75. Pingback: psikholog moskva
  76. Pingback: Dim Drakona 2022
  77. Pingback: TwnE4zl6
  78. Pingback: psy 3CtwvjS
  79. Pingback: lalochesia
  80. Pingback: buy viagra online
  81. Pingback: online drug store
  82. Pingback: film onlinee
  83. Pingback: 3qAIwwN
  84. Pingback: stromectol generic
  85. Pingback: video-2
  86. Pingback: sezons.store
  87. Pingback: stromectol stock
  88. Pingback: psy-news.ru
  89. Pingback: ivermectine
  90. Pingback: 000-1
  91. Pingback: 3SoTS32
  92. Pingback: 3DGofO7
  93. Pingback: canadian pharmacys
  94. Pingback: canadian pharmacy
  95. Pingback: cialis from canada
  96. Pingback: canadian rx
  97. Pingback: rftrip.ru
  98. Pingback: stromectol oral
  99. Pingback: canadian pharmacys
  100. Pingback: dolpsy.ru
  101. Pingback: canadian drugs
  102. Pingback: stromectol cvs
  103. Pingback: kin0shki.ru
  104. Pingback: 3o9cpydyue4s8.ru
  105. Pingback: mb588.ru
  106. Pingback: newsukraine.ru
  107. Pingback: edu-design.ru
  108. Pingback: tftl.ru
  109. Pingback: buy ivermectin
  110. Pingback: is stromectol safe
  111. Pingback: stromectol buy
  112. Pingback: brutv
  113. Pingback: canada rx
  114. Pingback: site 2023
  115. Pingback: pharmacy
  116. Pingback: buy viagra usa
  117. Pingback: drugstore online
  118. Pingback: pharmacy
  119. Pingback: canada pharmacies
  120. Pingback: canada drugs
  121. Pingback: sitestats01
  122. Pingback: 1c789.ru
  123. Pingback: cttdu.ru
  124. Pingback: canadian pharmacy
  125. Pingback: 1703
  126. Pingback: hdserial2023.ru
  127. Pingback: serialhd2023.ru
  128. Pingback: matchonline2022.ru
  129. Pingback: bit.ly/3OEzOZR
  130. Pingback: bit.ly/3gGFqGq
  131. Pingback: bit.ly/3ARFdXA
  132. Pingback: bit.ly/3ig2UT5
  133. Pingback: bit.ly/3GQNK0J
  134. Pingback: bep5w0Df
  135. Pingback: www
  136. Pingback: canada pharmacy
  137. Pingback: icf
  138. Pingback: 24hours-news
  139. Pingback: rusnewsweek
  140. Pingback: uluro-ado
  141. Pingback: irannews.ru
  142. Pingback: klondayk2022
  143. Pingback: drugs for sale
  144. Pingback: canadian pharmacy
  145. Pingback: tqmFEB3B
  146. Pingback: canada medication
  147. Pingback: online pharmacy
  148. Pingback: mangalib
  149. Pingback: drugstore online
  150. Pingback: x
  151. Pingback: 9xflix
  152. Pingback: xnxx
  153. Pingback: 123movies
  154. Pingback: kinokrad
  155. Pingback: batmanapollo
  156. Pingback: canadian rx
  157. Pingback: drugstore online
  158. Pingback: vsovezdeisrazu
  159. Pingback: 2023
  160. Pingback: ipsychologos
  161. Pingback: yug-grib.ru
  162. Pingback: studio-tatuage.ru
  163. Pingback: canada drug
  164. Pingback: video.vipspark.ru
  165. Pingback: vitaliy-abdulov.ru
  166. Pingback: psychophysics.ru

Comments are closed.