icriteria

Nhibernate - Paging and eager loading entities

I have two entities, a team and an employee. I want get a list of employees with eager loaded teams. The list has to be paged. public PagedList<Employee> GetAllEmployeesWithEagerLoadedTeams(int page, int pageSize) { var criteria = GetSession() .CreateCriteria(typeof (Employee)) .SetFetchMode(DomainModelHelper.GetAss...

NHibernate - Paging with ICriteria and optional ICriteria calls

I want to do something like this... return GetSession() .ToPagedList<Employee>(page, pageSize, x=> x.SetFetchMode(DomainModelHelper.GetAssociationEntityNameAsPlural<Team>(), FetchMode.Eager)); But I don't know how to pass this Func<ICriteria,ICriteria> into the ISession or ICriteria. I have a standard paging ext...

Sorting two columns using NHibernate Criteria API

I need to sort a result set by two columns, one of which is always NULL. A simplified view of Database where the columns I wish to sort on look like : ColumnA is from Table A Column B, B1 is from table B ColumnA ColumnB ColumnB1 U NULL NULL P NULL NULL L NULL NULL NULL U NULL NULL ...

Prevent NHibernate from aliasing in ORDER BY

I have a query which has an Order By clause. The generated SQL from NHibernate looks like ORDER BY coalesce(x.Company as x__.Company, y.Company) asc This fails as 'as' is not allowed in Order by clause in MS SQL Server. Is there any way I can prevent aliasing? The criteria query that I have written looks like: var orderBy = Proj...

Select where CONVERT() in NHibernate

Hello I want to generate a sql query with ICriteria interface like that select * from tableName where (dataColumn like '%2010-06-09%') I researched in google and I found CONVERT() function to do this: SELECT * FROM DATE_SAMPLE WHERE CONVERT(CHAR(10),SAMPLE_DATE,120) = '2003-04-09' How can I do this in NHibernate wtih ICriteria? ...

Distinct elements using NHibernate ICriteria for pagination

I am implementing a pagination solution using NHibernate ICriteria where I wish to display distinct elements within the page. The ICriteria for this is: Session.CreateCriteria(typeof(Employee), "a") .CreateCriteria("Company", "b") //BUNCH OF JOINS .SetProjection(Projections.ProjectionList() ...

NHibernate: Querying with OR operator

I am looking for a way to build an OR operator into a query to look for a particular value in one field of a table as well as in another field of a joined table. This is pretty basic in SQL, but I can't for the world figure out how to do this in NHibernate. I have been searching the web, but the examples I find are pretty nebulous to me ...

NHibernate: what's the differense between DetachedCriteria and ICriteria

this classes have some similar methods but seems to work slightly different. What's the difference of them and when should I use each of them? ...

query many-to-many nhibernate when only one side is mapped

I have the following entities public class Client { public virtual int Id{get;set;} public virtual IList<Telephone> Telephones { get; private set; } } public class User { public virtual int Id{get;set;} public virtual IList<Telephone> Telephones { get; private set; } } public class Telephone { public virtual int Id...

How to run Nhibernate ICriteria query with setFetchMode(Lazy) when lazy=false defined in HBM?

Hi all, I'd like to run a criteria query with lazy many-to-one associations. Those associations are set as lazy="false" in the HBM. It's because we use it eagerly 90% of the project. But there are a few 'big' queries that should run as lazy="proxy". HBM: <many-to-one name="DestinationElement" class="X" column="DstElemId" not-null="tr...

NHibernate correlated subquery using ICriteria

Hi All, I've been doing some work evaluating NHibernate for an upcoming project and am working through some use cases to see how it performs. I haven't yet been able to find a way to express the following query using the Criteri API. Two fairly basic tables (cut down for the purpose of this example) CREATE TABLE Person ( PersonNo ...