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

NHIbernate Conditional projection queries

I have requirement, wherein I have to calculate totals for cash and credit cards separately using conditional projection queries. My below code doesnt work and it gives me datatype mismatch error. Its says the true condition returns decimal and…
developer
  • 5,178
  • 11
  • 47
  • 72
0
votes
1 answer

Hibernate Criteria Pagination

What I need is add "pagination" in a List of a Class. Ej: Class A List B so I need limit the list of B to certain value What I'm doing is (Using Criteria, and it's all dynamic): ICriteria criteria = Session.createCriteria(); ICriteria…
aivaldi
  • 67
  • 2
  • 12
0
votes
1 answer

HQL Query that returns column of type string

how to retrieve a single column's value of type string using HQL. I tried the following way but is not working. public virtual string GetCityById(int Id) { using (var session = sessionFactory.OpenSession()) { …
navule
  • 3,212
  • 2
  • 36
  • 54
0
votes
1 answer

GenericADOException was unhandeled using Nhibernate CreateSQLQuery() method

whats wrong with the following code? public IList GetPostsByUser(object UserId) { using (var session = sessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { …
navule
  • 3,212
  • 2
  • 36
  • 54
0
votes
1 answer

SELECT TOP 10 FROM T using CreateQuery/CreateCriteria/QueryOver at Repository Level not at Entity Level

I have been facing problem fetching the latest 10 posts made by user. I wrote the following Nhibernate query as follows. public IList GetLatest10Posts() { using (var session = sessionFactory.OpenSession()) using (var…
navule
  • 3,212
  • 2
  • 36
  • 54
0
votes
1 answer

Efficient complex NHibernate Criteria query

I have an APVendor class, which has a collection of APInvoice classes and a unique Name; each APInvoice has a collection of APPayment classes. Each APPayment object references exactly one BankAccount class, a ClearedDate, an Amount, and a…
Jeremy Holovacs
  • 22,480
  • 33
  • 117
  • 254
0
votes
1 answer

Filtering only negative values using nhibernate projection queries

I am trying to filter only negative values using nhibernate projection queries. Below is my code for it SearchTemplate RefundTemplate = new SearchTemplate(); RefundTemplate.Criteria = DetachedCriteria.For(typeof(AirBilling), "Ab"); …
developer
  • 5,178
  • 11
  • 47
  • 72
0
votes
1 answer

(N)Hibernate : Search against 2 fields at once

In my project, I have a Member class with: public virtual string FirstName; public virtual string LastName; I'm familiar with using Criteria and Disjunctions to search against the columns individually, but how can I set things up so that "Davie…
user321605
  • 846
  • 2
  • 7
  • 20
0
votes
1 answer

query from nhibernate Criteria api to linq

I want to translate following query from nhibernate criteria query api to linq. var userquery = session.CreateCriteria(typeof(User)) .SetFirstResult(pageIndex * pageSize) .SetMaxResults(pageSize); var totalcountQuery =…
Grunf
  • 482
  • 8
  • 21
0
votes
1 answer

How to hide some fields using NHIbernate ICriteria?

Here's a scenario that I am working on : Right now we have a SQL statement that reads like this : SELECT a.ID,a.MsgNumber,CASE WHEN @HasAccess=1 THEN Title ELSE '*********' END AS Title FROM Messages We want that operators be able to see if a…
Beatles1692
  • 5,214
  • 34
  • 65
0
votes
1 answer

Using NHibernate and Repository pattern - how to handle mocking the context and filter expressions

I'm working on project that uses NHibernate 3, but the code is pretty messy. What I would like to do is: introduce testing code into project introduce Repository pattern - I did it in projects with Entity Framework 4, and I enjoyed it, especially…
dragonfly
  • 17,407
  • 30
  • 110
  • 219
0
votes
1 answer

NHibernate filter collection and parent

I have an object "Owner" with collection property "Cars". I want to filter Owners based on Cars criteria (Ex: All Owners with Red Cars) and I dont want to query non red cars for SomeOwner.Cars. So I want one query filter for both parent and…
Vladimir Nani
  • 2,774
  • 6
  • 31
  • 52
0
votes
1 answer

How to select tasks where userName is "xx"

I have 2 tables (Task table and user table) task table have list of users how to select tasks where userName is "xx" using criteria in nhibernate 2
Amir Salah
  • 31
  • 9
-1
votes
1 answer

SQL query to criteria nhibernate

Hello. I have a problem with the creation of a Hibernate Criteria object. I'm new to Hibernate. Can someone help me with the creation of a complex Criteria object and explain how this is done? Here is the sample SQL select statement to…
Endiss
  • 699
  • 2
  • 10
  • 23
-1
votes
1 answer

Distinct query in Criteria NHibernate

I need the corresponding query in Criteria language to this one (to retrieve all categories from my table but to distinct them): SELECT DISTINCT categoryName FROM Category WHERE CategoryID IN ( SELECT CategoryID …
1 2 3
19
20