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
2
votes
1 answer

How can I query a list of key value pairs using NHibernate ICriteria?

I have a class with a number of fields, one being an IList>. public class Foo { public IList> Bars { get; set; } } I'm using Fluent NHibernate and that particular field is mapped as…
Owen Pauling
  • 11,349
  • 20
  • 53
  • 64
2
votes
1 answer

NHibernate Criteria: Subquery After 'From' Clause

How can I write the following SQL using Criteria: select b.Name as Batch, b.Capacity as Capecity, a.tStudent as Admit, (b.Capacity-a.tStudent) as Availabe from ( SELECT count(Id) as tStudent, BatchId FROM [dbo].[Student] group by BatchId)…
Habibul Morsalin
  • 180
  • 1
  • 11
2
votes
2 answers

CreateCriteria over a collection of simple types

How can I query using CreateCriteria over a collection of simple types? For example, I have 1 class public class Test { public virtual Guid Id { get; set; } private ICollection _values = new HashedSet(); public virtual…
user1582878
  • 273
  • 2
  • 7
2
votes
1 answer

nHibernate QueryOver Inheritance

I have something like this : public class User { /* some properties */ public virtual int Id { get; set; } public abstract string LastName { get; } } public class Student { public virtual int Id {…
2
votes
1 answer

NH QueryOver - use properties of main query in subquery

I am trying to convert following SQL to QueryOver: Select 1 From myTable mt Where mt.ForeignKey in (select ID from otherTable ot where ot.ID = R.ID) I want to use this subquery inside an EXISTS / NOT EXISTS statement like: select * from table R…
Philipp
  • 649
  • 2
  • 7
  • 23
2
votes
1 answer

Fluent NHibernate - ProjectionList - ICriteria is returning null values

I'm quite new in NHibernate, but I have googled around and didn't found anything to help with this issue. I hope you guys can ! ;) I'm changing names of properties, and methods, because this code is company's property but basically this is what I…
2
votes
2 answers

NHibernate multiple inner join select

I'm trying to get NHibernate to do a simple query based on the inner joins of 3 tables: var sessionCriteria = session.CreateCriteria("M") .CreateCriteria("Accounts", "A",…
MrTibs
  • 161
  • 1
  • 12
2
votes
1 answer

JPA CriteriaBuilder - Use of Multiselect with select count(*)

Is it possible to use the query result as column in my final query resultset with Multiselect? For example: Query 1: select EMPLOYEE_NAME name, (Query 2) TOTAL_WORKING_DAYS FROM EMPLOYEE; Query 2: select COUNT(*) from WORKING_DAYS; I was trying…
Sudipta Deb
  • 1,040
  • 3
  • 23
  • 43
2
votes
1 answer

NHibernate child collection Projection to DTO

I have had a good look around for answers on this, and several questions suggest this cannot be done. Nhibernate projection with child collection NHibernate QueryOver projections - projecting collections to DTO NHibernate Projections - how to…
jonho
  • 1,680
  • 2
  • 19
  • 29
2
votes
1 answer

NHibernate QueryOver (generic), tell query which properties of generic class it should use

it's my first time in NHibernate QueryOver and I'm trying to do it in a generic way. So far, this is what I have done.. //Find one only public T Find(string propertyName1, string propertyName2, string value1, string value2) { using (var session…
raberana
  • 11,739
  • 18
  • 69
  • 95
2
votes
1 answer

How can I select a column within a dictionary value with nhibernate?

I have structure similar to this: public class Entity { public int Id { get; set; } public IDictionary Locales { get; set; } } public class EntityLocale { public string Name { get; set; } } public class EntityMap :…
Adam Tal
  • 5,911
  • 4
  • 29
  • 49
2
votes
1 answer

NHibernate QueryOver - Join without path (or with "reversed" path)

I am trying to fetch several entities without having a single root entity ( the directed graph of entity-relations is only a weakly connected graph, not strongly connected) and I cant figure out how to do it in Nhibernates QueryOver api (or Linq,…
Tomas Grosup
  • 6,396
  • 3
  • 30
  • 44
2
votes
0 answers

nhibernate criteria set the alias of a subclass parent?

I have an abstract base class that contains a property called "DateCreated"; it has a number of child classes, some of which link to each other. When I try to query against one of the child classes, I get an ambiguous column error with DateCreated,…
user1838662
  • 503
  • 7
  • 17
2
votes
1 answer

Explain the difference between CreateCriteria(typeof(Cat)) and CreateCriteria()

I've seen both formats in different examples, tutorials, blogs, etc, but for the life of me, I cannot find an explanation for the difference. What is the difference between ICriteria crit = session.CreateCriteria(typeof(Cat)); and ICriteria crit =…
Miaka
  • 63
  • 5
2
votes
1 answer

Row_Number() with partition in Nhibernate using CreateCriteria

I am stuck in a problem while creating a query in nhibernate in c#. Actually I have to create a criteria query for following sql statement select fCompanyID,ROW_NUMBER() over( PARTITION BY fCompanyID order by fPropertyID) from tARCustomer But it…
Awadhendra
  • 355
  • 2
  • 10
  • 34