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

Nhibernate n+1 with ternary relationship. Want the middle entity in the ternary

I'm having a huge issue with nhibernate n+1 and nothing I try seems to fix the problem. Nhibernate profiler still shows n+1 selects hitting the database. Here's my model: public class CustomerGroup : CoreObjectBase { public virtual long GroupId…
Josh
  • 16,286
  • 25
  • 113
  • 158
4
votes
3 answers

Nhibernate row number over partition c#

I an new in nhibernate and need your help. How can I execute this sql query in nhibernate-criteria C# select * from ( select *, row_number() over (partition by questionaireId order by stepnumber desc) rid from myTable ) t where t.rid=1
zina
  • 258
  • 2
  • 9
3
votes
3 answers

How to 'translate' the SQL's EXCEPT to (N)Hibernate (Criteria API)?

I'm working on a case were I normally, in SQL, should have an 'except' keyword. At this moment I didn't found a solution to accomplish this in NHibernate. It's a solution where you have two tables: The user table and a FK table (including a PK for…
Gigi2m02
  • 1,238
  • 3
  • 17
  • 33
3
votes
2 answers

NHibernate converting string parameters to nvarchar instead of varchar. How can I stop this?

I have a class mapped to a view and am searching on first and last names in order to search for patient records. The view ultimately looks at the first and last name fields on the patient table (possibly others as well depending on input). When…
3
votes
2 answers

NHibernate - fetching with futures

I have this Fluent NHibernate mapping: public LossMap() { Table("losses"); Id(x => x.Id).Column("id"); References(x => x.Policy).Column("pol_id"); HasMany(x => x.Statuses).KeyColumn("loss_id").Cascade.All().Inverse(); HasMany(x…
user315648
  • 1,945
  • 3
  • 22
  • 30
3
votes
1 answer

Loading multi-level collections without duplicates in NHibernate

My question is very similar to this one (that wasn't really answered): Nhibernate: distinct results in second level Collection I have this object model: class EntityA { ... IList BList { get; protected set; } …
dstj
  • 4,800
  • 2
  • 39
  • 61
3
votes
1 answer

How to get the value from a subquery in NHibernate?`

I'm currently building a message board where I need to output the number of messages in a Thread. ID Name MessageCount In plain SQL it would look like this but I can't find any documentation on how to make the inline select. SELECT t.ID, t.Name…
Jonas Stensved
  • 14,378
  • 5
  • 51
  • 80
3
votes
1 answer

Passing Object Type into method as a Parameter?

I have the following method that returns a Person object by Id: private Person getPersonById(String client) { Person output = null; EntityManager entityManager = null; try { entityManager =…
java12399900
  • 1,485
  • 7
  • 26
  • 56
3
votes
2 answers

Hibernate Criteria: Projecting Count with group by clause

I want to execute the following SQL select count(*) as myCount from user group by name; I came up with the following criteria for the same DetachedCriteria.ForClass(typeof(UserDTO)) .setProjections(Projections.ProjectionList() …
frictionlesspulley
  • 11,070
  • 14
  • 66
  • 115
3
votes
1 answer

How to select top 10 most sold products in NHibernate?

This solution didn't work for me: C#/NHibernate - Get first 10 records ordered by grouped sum My case is very similar, but I keep receveing the following error message: Additional information: could not resolve property: Produto_Id of:…
Latrova
  • 468
  • 6
  • 15
3
votes
1 answer

Can I create a custom expression without using the where clause?

While I have already solved this issue in a previous question using a native query. I am now wondering if it is possible to create a custom expression that is usable in a Criteria without using the where clause? The reason I don't want the where…
Mike
  • 4,257
  • 3
  • 33
  • 47
3
votes
1 answer

Dynamic conjunction building for Nhibernate QueryOver in c#

Im trying to build somewhat of filter builder for my collections. public static NHibernate.Criterion.Conjunction CreateConjunction(this IEnumerable _filters) { NHibernate.Criterion.Conjunction conjunction =…
PabloPC
  • 41
  • 4
3
votes
1 answer

NHibernate Filtered Child Collection Lazy Loaded even with eager fetch specified

Im trying to find out why a child collection is being returned without filtering even when eager loading the collection and the generated SQL is correct. The fluent mappings for the classes are: public class OptionIdentifierMap :…
3
votes
2 answers

Criteria join with projection

I am going to create this SQL query's Criteria equivalent: SQL: SELECT orders.id, book.title, orderitem.quantity FROM orderitem INNER JOIN book ON book.id = orderitem.book_id INNER JOIN orders ON orders.id =…
user4832640
3
votes
1 answer

NHibernate Criteria Query vs. LINQ to NHibernate

I understand that there are queries you can't express in LINQ to NHibernate that you can using NHibernate Criteria. But, as far performance, is it safe to assume that using NHibernate Criteria is generally better than LINQ to NHibernate?
Chris
  • 2,959
  • 1
  • 30
  • 46
1 2
3
19 20