Questions tagged [nhibernate-criteria]

The NHibernate Criteria API allows performing dynamic, object oriented queries in NHibernate.

Using the criteria API is one way to perform queries in NHibernate. Its strength is on writing dynamic queries at runtime. It lacks some features compared to HQL, for instance creation of cross products and joining objects on arbitrary properties.

Related:

  • QueryOver is a successor of Criteria, which provides more type safety at compile time, but is still base on Criteria.
  • Linq To NHibernate once based on Criteria, but had been rewritten to use HQL in later versions.

References:

286 questions
3
votes
1 answer

NHibernate COALESCE issue

I am trying to express the following SQL query with NHibernate DECLARE @date DATETIME = NULL; SELECT ER.Id , ER.DocumentDate FROM ExpenseReport ER WHERE ER.PeriodFrom >= COALESCE(@date, ER.PeriodFrom) OR ER.PeriodTo <=…
Dimi Takis
  • 4,924
  • 3
  • 29
  • 41
3
votes
1 answer

QueryOver: select ... where property in (...)

I try to use queryover to represent the following sql: select * from Table1 t1 where t1.foreign_key in (select t2.Id from Table2 t2 where (...)) So I created a subquery for the inner select statement like this: var sq =…
Philipp
  • 649
  • 2
  • 7
  • 23
3
votes
2 answers

Using SQL CONVERT function through nHibernate Criterion

I have a sql view, in which the data type of every column is string, for use with the jquery datatables plugin. One of the columns contains a uk format date dd/mm/yyyy. This column needs to remain a string to work with the keystroke filtering of…
Declan McNulty
  • 3,194
  • 6
  • 35
  • 54
3
votes
1 answer

Where clause with type check "is" operator does not use discriminator

I have mapped a class hierarchy in NHibernate. Simple as that: class abstract Animal class Dog : Animal class Cat: Animal class Cow: Animal In mapping I have discriminator values set on ANIMAL_TYPE column: Dog -> dog Cat -> cat Cow -> cow All…
dragonfly
  • 17,407
  • 30
  • 110
  • 219
3
votes
1 answer

Nhibernate QueryOver Get all Parents with less than 3 childs

I am fighting with this query since yesterday morning and cannot find a solution. What I want to do is to have a query like: IList = _session.QueryOver() .Where(Restrictions.lt(x => x.Childs.Count,4)) .List(); Anyone…
3
votes
1 answer

NHibernate many-to-many criteria creating multiple database calls

I have Events, which can have many EventTypes. I'm attempting to query the database by using the NHibernate mappings I have defined. The issue is that when defining criteria on child objects, NHibernate makes repeated calls to the database, rather…
3
votes
3 answers

Incorrect Syntax near "?" : Nhibernate Generated Query

I am getting problem while working with positional parameters in Nhbernate. Criteria GroupProperty is emitting sql with both named and positional variables. This statement: session.CreateCriteria(typeof(MatchStageFrom)) …
K D
  • 5,889
  • 1
  • 23
  • 35
2
votes
2 answers

QueryOver fails with could not resolve property:

I am using NHibernate 3.0 and was comparing Query and QueryOver var p = _prepo.Query() .Where(c => c.Person.LastName == "Bobby") .FirstOrDefault(); The above works, I get proxy class for p.Person if I view the object…
user357086
  • 404
  • 1
  • 9
  • 23
2
votes
0 answers

NHibernate multiple joined subclasses and duplicate column names using criteria

Assume we have this entity structure: Document - DocumentA - DocumentB In base class Document we have fields Id, Name, CreateDate. In joined subclass DocumentA we have fields Book, Pages. And in DocumentB we have Magazine, Pages. So the problem is…
2
votes
1 answer

Catching the NHibernate generated SQL and amending before running

Is it possible to obtain the sql that would be created by nhibernate in your code without actually running it? I have a complex criteria object that I have built through the criteria API. This criteria object forms the base of various select…
fluent
  • 2,393
  • 4
  • 22
  • 32
2
votes
0 answers

nHibernate: Using entity-name with QueryOver and CreateCriteria

I have two hbm.xml mappingfiles. They are identical except for the class table and class entity-name properties. They are supposed to populate the same Entity. They have entity-name= Alpha and Beta, table= PersonAlpha and PersonBeta respectively. I…
Vegard
  • 35
  • 1
  • 8
2
votes
1 answer

NHibernate projecting a collection of elements

I want to select all requests that are outstanding for a given manager. A manager can have multiple teams. I compose the queries applying various restrictions based upon permissions, and alter the queries to provide row counts, existence checks, sub…
Chris Chilvers
  • 6,429
  • 3
  • 32
  • 53
2
votes
0 answers

NHibernate QueryCache in Multiuser-Environment

For our web-application (ASP.NET) we're using Fluent NHibernate (2.1.2) with 2nd-Level caching not only for entities, but also for queries (generating queries with the criteria API). We're using the Session-Per-Request pattern and one SessionFactory…
2
votes
1 answer

How to fetch objects multiple levels deep and wide with NHibernate?

I have a case where I need to load about 10 000 objects from database. The data model is something like this: public class SimulationObject { public Container Container {get;set;} public IList Results {get;set;} public…
2
votes
0 answers

Nhibernate - QueryOver JoinAlias Which has no relational Mapping

I have to join two tables, but there is no for those fields. Is it possible to do it? For example TableA (ID, MachineID, EquipmentID) Machine (MachineID, Description) There is a mapping for TableA.MachineID => Machine.MachineID. I can use Join for…
DineshNS
  • 3,490
  • 5
  • 26
  • 28