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

Retrieving Navigation Properties with NHibernate Criteria

I think I'm just searching for the wrong terms, since I can't seem to find an answer to what I'm fairly sure is a simple question. I have two classes/mappings (simplified); public class Applications { public int Id {get; set;} public string…
Trent
  • 1,595
  • 15
  • 37
0
votes
1 answer

NHibernate: how to express a specific "group by" query with criteria

Question: What are the criteria/projections that can generate a following query? SELECT SUBSTRING(Name, 0, 1) FROM Person GROUP BY SUBSTRING(Name, 0, 1) (Obviously this one is easier with DISTINCT, but I'll need counts later, when I fix this one). …
0
votes
1 answer

How do I use the Criteria API to query primitive types in a many-to-many relationship?

I have a "bookmark" entity that has tags which are strings. In C#, the bookmark Poco is similar to: public class BookmarkEntity { public virtual Guid Id { get; set; } public virtual ISet Tags { get; set; } } I've automapped the…
Patrick Quirk
  • 23,334
  • 2
  • 57
  • 88
0
votes
2 answers

Or statements in criterion

I have a list of orders, which are connected to a user-table. Each order can contain multiple users. I then have a search area where an admin can search through all orders by searching for e.g. a last name. If there is done a search for e.g. Smith,…
Dofs
  • 17,737
  • 28
  • 75
  • 123
0
votes
1 answer

NHibernate SetFirstResult causes duplicate results

We are having trouble with the way NHibernate (version 4.0.0.4000 AND 4.0.4.4000 tested) returns duplicate results. In the sample below, I get 566 results (the correct number of results), but only 549 are unique, meaning there are 17 duplicates. …
dythim
  • 920
  • 7
  • 24
0
votes
1 answer

FluentNhibernate Criteria LeftOuterJoin Generates duplicate rows

Suppose I have following classes : public class Fund : EntityBase { public virtual string Name { get; set; } public virtual IList FundDetails { get; set; } public virtual IList FundAliases { get; set;…
Nic
  • 1,088
  • 3
  • 19
  • 43
0
votes
1 answer

Fluent Nhibernate QueryOver using "Or" and "And clause"

Suppose I have following domain models: public class Fund : EntityBase { public virtual string Name { get; set; } public virtual IList FundDetails { get; set; } public Fund() { …
Nic
  • 1,088
  • 3
  • 19
  • 43
0
votes
1 answer

Hibernate Criteria: subquery with IN

First question here: I am using DB2 and Java Hibernate criteria. I need a way to use a subquery in my where clause and be able to use IN in the subquery. But I cannot seem to find the solution. This is what I have…
Dries
  • 1
0
votes
1 answer

combining QueryOver and CreateQuery subquery

I'm using QueryOver<> to execute a series of subqueries using a conjunction. Here is some psuedo code that explains what I'm doing: Conjunction conj = new…
Chet
  • 199
  • 10
0
votes
1 answer

Nhibernate v2.1.2 criteria fetch adding some days to modifiedon > datetimenow

Want to achieve something like **ModifiedDate.AddDays(20) > current datetime ** Where the modifiedondate is added with a configurable value and which is again compared with whether it is greater than the current datetime. For example in DB I…
Vinay
  • 471
  • 3
  • 8
  • 19
0
votes
1 answer

Nhibernate SetFetchMode - Inner vs Left Outer Join

All, I have an entity called Client that has an association to an entity called Region as: Client -> Region All my entities are Lazy loaded (nhibernate default setting). Region in Client is mapped as NotNull = false: [ManyToOne(Column =…
ActiveX
  • 1,064
  • 1
  • 17
  • 37
0
votes
1 answer

How Do I Query Objects With Nested Properties Using NHibernate?

Okay, I've seen some similar questions to this, but the answers either confused me or seemed completely over-engineered, so I'd like to ask my own question. I have a class called Tree, which has an object property from the class Plot, which has an…
Rabadash8820
  • 2,328
  • 3
  • 27
  • 49
0
votes
1 answer

How to add a true/false to a disjunction/conjunction in nhibernate?

I saw a few older posts mentioning MyDisjunction.Add(Restrictions.Sql("(1=1)")), but I couldn't find the Sql function (does it still exist?). Instead, I am using MyDisjunction.Add(Restriction.Where(x => x.SomeProperty == x.SomeProperty))…
Lawtonfogle
  • 974
  • 4
  • 17
  • 32
0
votes
1 answer

Best approach to add a case in a column for nhibernate

What is it the best way to add this query as projection in an nhibernate? CASE WHEN account.firstname = '' AND account.lastname = '' THEN email.EmailAddress ELSE account.firstname + ' ' + account.lastname END
0
votes
2 answers

Make a SQL Query to Nhibernate

How do I get this SQL query to Nhibernate? SELECT Customer.name FROM Company INNER JOIN Customer ON Company.CompanyId = Customer.CompanyId where CompanyId = 2
user3635120
  • 73
  • 3
  • 10