icriteria

nHibernate Criteria Query OR or IN?

Hi there people. I need to recreate a query using nHibernate Criteria. This query had a where clause that was pretty ugly. ((t.Disposition_CD)='ac' Or (t.Disposition_CD)='cc' Or (t.Disposition_CD)='Co' Or (t.Disposition_CD)='SF' Or (t.Disposition_CD)='SC' Or (t.Disposition_CD)='OR' Or (t.Disposition_CD)='SV' Or ...

NHibernate ICriteria and Expected Types

Is there any way to get at the types of objects I would expect NHibernate to place in an ICriteria object as the result of running a query? In this code sample, I can get at the types of my objects if they aren't null, but what if they are? Also, depending on the data returned, one "row" (object[]) may have null fields in places where ot...

How to query a subproperty with NHibernate’s criteria api and the entity to load only the subproperties matching a predicate condition...

Assuming the following: public class Order { public virtual int OrderId {get;set} public virtual ISet<Product> Products {get;set} } public class Product { public virtual int ProductId {get;set} public virtual string ProductName {get;set} } How would you query using the criteria api so that only an order with a specific o...

NHibernate - Implement "NOT IN" query using ICriteria

I've started getting to grips with NHibernate. I'm trying to perform a query that selects all records from a table but with an exclusion filter list of IDs, eg. get me all Products except these ones with these ID values. Normally in direct T-SQL I'd pass in the IDs to be excluded into a NOT IN clause like so. SELECT * FROM Products WHE...

How to use NHibernate's Session.Criteria with multiple foreign keys?

I'm trying to create a query using NHibernate and searching along multiple foreign keys: The following code works when I'm only searching on one of the foreign keys: ICriteria query = Session.CreateCriteria<TblTeam>() .Add<TblTeam>(x => x.FldUrlSafeName == teamName) .CreateCriteria<TblTeam>(x => x.TblSportsType) .Add<Tbl...

NHibernate How do I query against an IList<string> property?

I am trying to query against an IList<string> property on one of my domain classes using NHibernate. Here is a simple example to demonstrate: public class Demo { public Demo() { this.Tags = new List<string>(); } public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual IL...

Projections.Conditional - How to use it?

Hi Anyone knows how to use Projections.Conditional to produce something like "case ... when..." The following code gives a wrong query: IProjection isError = Projections.Conditional( Expression.Eq( "event.LogLevel", eLogLevel.Fatal.ToString( ) ), Projections.Constant( 1 ), Projections.Constant( 0 ) ); ICriteria criteria = Session.Cre...

How to Determine the Sort Order of an NHibernate ICriteria Object?

What is the best way to retrieve the list of Orders added to an ICriteria object using the AddOrder method? I believe this will have to be accomplished using Reflection, but what to reflect on? The purpose of doing this is that I would like to pass the sort order back to the UI so an indication of the sort order can be provided to the u...

Nhibernate Criteria: 'select max(id)...'

Can I use a Criteria to execute a t-sql command to select the max value for a column in a table? 'select @cus_id = max(id) + 1 from customers' Ta Ollie ...

What's the difference/advantages between ICriteria and ICriterion in nHibernate?

Bit of a newbie question as Im getting started with nHibernate. What's the difference between NHibernate.Criterion.ICriterion and NHibernate.ICriteria classes and which should I use for simple "where field=value" type filtering? ...

Nhibernate NullReferenceException returning List of domain objects

Following is the code I am using. Seems pretty simple to me. But I get a NullReferenceException at the last line , the return statement. Here is the stack trace: FailedSystem.NullReferenceException: Object reference not set to an instance of an object. at NHibernate.Criterion.Junction.ToSqlString(ICriteria criteria, ICriteria...

NHibernate - need help with ICriteria query

I am having trouble getting my query by criteria to work. I want to filter the UserPublications collection by userId but it is not filtering. The ClientPublications collection has filtered correctly though. Any advice? Thanks in advance. public IList<ClientReport> GetAvailableClientReports(int userId) { ICriteria criteria...

Using NHibernate Criteria API to select sepcific set of data together with a count

I have the following domain set up for persistence with NHibernate: I am using the PaperConfiguration as the root aggregate. I want to select all PaperConfiguration objects for a given Tier and AcademicYearConfiguration. This works really well as per the following example: ICriteria criteria = session.CreateCriteria<PaperConfiguratio...

How to get this kind of query in NHibernate : SELECT DISTINCT FileName From CustomerFile WHERE name = ' ' AND timeframe = ''

Please do not redirect me towards the other similar kinds of HQL in Stackoverflow, because they did not work for me. I really appreciate your direction on it. Thanks. Reproducing this kind of query in Nhibernate with ICriteria API : SELECT DISTINCT FileName From CustomerFile WHERE name = ' ' AND timeframe = '' ...

Creating reports with NHibernate

I have the following entities (simplified for this example) mapped using Fluent NHibernate: public class Stock : Security { public virtual string TickerName { get; set; } public override string GetName() { return TickerName; } } public class Fund : Security { public virtual string FullName { get; set; } public virtual string Ti...

NHibernate Search with inheritance ...

Hello guys... I have a Client class like that: public class Client { public Person Pers { get; set; } } And I have 2 Person´s child class : public class PersonType1 : Person { protected string att1; protected string att2; } public class PersonType2 : Person { protected string att3; protected string att4; } pu...

Nhibernate criteria query - ordering a collection

I have a Person class. A person class contains a collection of Friends (also Person objects). A person class also has a LatestLogin property which is the LatestLogin time. For a given person, I want to return their first 10 friends ordered by descending LatestLogin. HQL I can do no problem: select friends from Person person inner jo...

NHibernate Lambda Extensions - Eager Loading a collection's assosciations

I've got a Criteria Query for a social networking site. A Person object has a collection of Friends (also person objects). The query grabs the first N friends, but I also want to eager load an associated object MainProfileImage and then a subsequent associated object MediumThumbnail. I can do this in HQL easily: select friends from P...

Removing Order from NHibernate Criteria Query

I have a criteria query that I am using to show pages of results. I also need to obtain the total count of all items. Rather than have two queries, one for paging the results and one for the count (since they are identical apart from the .AddOrder() public ICriteria StandardQuery { get { return NHibernateSesssionManager.Ge...

NHibernate Criteria Query - Select Distinct

I have a Person entity belongs to a person has a Country, I want to select all the distinct countries that have people in them. Easy in HQL select distinct p.Country from Person p How can I do this using a Criteria Query? ...