nhibernate-criteria

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? ...

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). My approaches: My main problem here is with constants, because if I use Projecti...

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 clause is because Oracle's connect by ... start with ... (here) statement. I followed this pa...

How do I use NHibernate criteria queries to load associations based on additional conditions

Let's say I have a Cat that has two properties: FavoriteKitten SecondFavoriteKitten These kittens are discriminated by their Rank. When loading a Cat, I want the kitten with the rank of "1" to be FavoriteKitten, and the kitten with the rank of "2" to be SecondFavoriteKitten. The underlying database looks like: table Cat ----------...

Using NHibernate Restrictions without strings in the property name.

When you create a criteria, you can add Restrictions that apply to a property. There are 2 ways of creating a Restriction: Restrictions.Eq(string propertyName, object value) or Restrictions.Eq(IProjection projection, object value) Thing is, I don't feel comfortable passing property names as strings, since if they ever change, my projec...

NHibernate do Update in Criteria.List

Hi, I'm trying to do select count(*) by ICriteria and when call to criteria.List it does update and after then it does the select clause The update is the object which is now in cache Example: I do Session.Get<...> and after then ICriteria criteria = Session.CreateCriteria(typeof(...)) .SetProjection(Project...

NHibernate - How to write this Query: Select parents & find child for each parent that matches a condition

OK, first my simple Domain Model is 2 classes with a one-to-many relationship, a simple Parent -> child relationship. A 'Tweet' has one or more 'Votes', but each Vote belongs to just one Tweets etc. public class Tweet { public virtual long Id { get; set; } public virtual string Username { get; set; } public virtual string Me...

How do I query by the count of a property in nhibernate without using a detached criteria?

hey guys, I'm using NHibernate version 2.1.2.4000. The Entity class bowl { int id { get; set; } List<fruit> fruits { get; set; } } The Desired (pseudo) Query var bowls = repository.where(b => b.fruits.count > 1); The Question How do I do the above query using the NHibernate criteria API? Ideally I'd like to be able to do...

Hibernate simple criteria query solving problem

I'm stuck with a very simple criteria query problem: sess .createCriteria(user.class, "user") .user_c.add(Restrictions.eq("user.status", 1)) .user_c.createAlias("user.userCategories","ucs") .add(Restrictions.eq("ucs.category_id",1)); .add(Restrictions.eq("ucs.category_id",'yes')); .add(Restrict...

Composite Id's and Restrictions.IdEq or with comparison in Linq not working as expected

I have an entity where a composite id is used. I changed to code to make use of wrapping the composite id in a seperate key class. I expected that with Linq I could do a comparison on key object and with the Criteria API to use Restrictions.IdEq but both fail. I need to explicitly compare the key values to make it work. I cannot find an...

NHibernate Criteria Queries Documentation

Does anyone know of a resource for Criteria Queries in NHibernate that demonstrates complex criteria restrictions. For example select rows in the parent table and only rows in a child table that match a criteria set eager fetching on parent and child in the criteria i.e. not just simple criteria, but something a bit more meaty. I ha...

Can you perform complex aggregate operations using NH3?

I need to perform a grouping aggregation similar to something like this in T-SQL: select b.Name as [Grouped Name], COUNT(distinct a.ID) as [Grouped Count], COUNT(distinct c1.ID) as [Second Group Count], COUNT(distinct c2.ID) as [Third Group Count] from TableA a left join TableB b on a.ID = b.TableAID left join TableC c1 on a.ID = c1.T...