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

NHibernate query to fetch top(x) entities for a given List property

I'm having difficulties figuring out how to do the following. Given the following classes: public class Post { ... public IList Comments ... } public class Comment { public DateTime CommentDate ... Some other…
StanK
  • 4,750
  • 2
  • 22
  • 46
2
votes
1 answer

NHibernate Futures vs CreateMultiCriteria

I have used both NHibernate Futures and NHibernate CreateMultiCriteria in the past to batch sql queries. Are there any reasons why I would want to use one or the other. Are both of those methods equivalent or is it a matter of preference?
Phil
  • 4,134
  • 4
  • 23
  • 40
2
votes
0 answers

How to eager load lazy-loading properties/components with NHibernate Criteria API?

I have a lazy-loading property (component) in one of my entity classes. In HQL I can write "fetch all properties" to eagerly load it. Can I do the same with Criteria API? I tried criteria.SetFetchMode("PropertyName", FetchMode.Eager) but is not…
Vasea
  • 5,043
  • 2
  • 26
  • 30
2
votes
2 answers

Hibernate IN/ANY with custom converter in Criteria

I have a simple model say class A { @Type(type = "com.vivek.persistence.ListAsSQLArrayUserType") @Column(name = "string_array", columnDefinition = "text[]") List stringArray; } Now I want to search any item…
2
votes
1 answer

Nhibernate projection with child collection

Using NHibernate 2.1, I'm trying to project an entity and its child collection into a DTO. My entity looks like this.. public class Application { public int Id {get;set;} public string Name {get;set;} public List Settings…
Rob Gibbens
  • 1,122
  • 1
  • 8
  • 24
2
votes
1 answer

Dynamic Data Querying using Entity Framework (EF)

I would like to hear some feedback on a scenario that I am trying to implement. I have currently implemented this scenario using Criteria API for NHibernate and was wondering if there was anything similar that was implemented for Entity Framework…
2
votes
1 answer

NHibernate 3 and Future with Lazy Load

I've got an entity Reminder which contains a collection of Schedules (see the mapping here). I didn't want my collection Schedules to be lazy loaded so I set the attribute to false:
LeftyX
  • 35,328
  • 21
  • 132
  • 193
2
votes
1 answer

how to get id of entity using nhibernate createcriteria

Newbie Alert I am trying to check if an entity exists in the database, if it does i want to update it else create a new entity. But CreateCriteria use always returns an entity with no id? Any ideas why? I am using fluent nhibernate for manual…
Ots K
  • 21
  • 1
2
votes
3 answers

How to resolve poor nHibernate collection initialization

nHibernate3; retrieving 4xxx records out of an EAV data schema. When nHibernate, or .NET, goes to initialize those collections for the first time, we're seeing a severe penalty. Subsequent calls appear to perform more efficiently. Running the same…
andrewbadera
  • 1,372
  • 9
  • 19
2
votes
1 answer

Criteria API and left join on a dictionary/map

I have the following classes: public class Item { public int Id { get; set; } public IDictionary { get; protected set; } public ICollection Tags { get; set; } public int DefaultLanguageId { get; set; } …
Ramon Smits
  • 2,482
  • 1
  • 18
  • 20
2
votes
0 answers

nhibernate criteria, like on words

I want to do this with a nhibernate criteria: SELECT Text FROM Table WHERE Text Like 'Re% Wi%' The result should be: Red Wine I have the search parameter as a string 'Re Wi' from the user interface. What is the best approach? split the string and…
Erik Sundström
  • 997
  • 1
  • 12
  • 29
2
votes
0 answers

Hibernate Subqueries

I have a situation where I need to convert a query like :- select hostname, avg(cpu_utilization_percentage) from cpu_utilization where timestamp In (select distinct(timestamp) from report.cpu_utilization order by timestamp desc limit 6) group by…
2
votes
0 answers

NHibernate criteria query that sums field from collection

I have a simple one-to-many relationship between table Order and table Line. I want a query that reports each Order entity and the sum of the Line.Value field. I can do this in HQL: select order, sum(line.Value) as LineValue from Order as order …
Rob Walker
  • 46,588
  • 15
  • 99
  • 136
2
votes
1 answer

How to get projected property in NHibernate?

Let's say I am using NHibernate and want to find some aggregate values of a set. I have something like this: var crit = session.CreateCriteria(); crit.Add(someRestrictions); crit.SetProjection( Projections.ProjectionList() …
Joseph Nields
  • 5,527
  • 2
  • 32
  • 48
2
votes
1 answer

How to get count of Junction criteries in NHibernate

I Compose NHibernate Query using Criterion Junction criterion = Restrictions.Conjunction(); criterion.Add(something1); criterion.Add(something2); .... criterion.Add(somethingN); and how can I get count of criteries in criterion like…