icriteria

NHibernate Criteria: concatenating two columns with an IN Expression

This is the SQL that I want to accomplish: WHERE domain_nm + '\' + group_nm in ('DOMAINNAME\USERNAME1','DOMAINNAME2\USERNAME2') I can't for the life of me find an appropriate Expression for this. And I don't think I can use two expressions as the domain name and the group name need to be concatenated. Thanks! ...

How to set more than 2 Expression in Expression.Or

I want to create a query which has more than 3-4 Expression.Or ? But Expression.Or just let me to add two Expressions inside it. if (!string.IsNullOrEmpty(keyword)) query .Add(Expression.Or( Expression.Like("Name", keyword, MatchMode.Anywhere), ...

HQL "Contains" statement howto?

Hi, I have an entity that has a string property called Tags. I would like to query this entity based upon if a certain string is located in Tags property. So for example, I would have a function IList GetEntityByTag(string tag), this would return all Entity's that have the value of tag in their 'Tags' property. I tried going through t...

Querying on Collection with Nhibernate Criteria Api ?

Hi, I have an "Estate" entity, and this entity has a collection "EstateFeatures"(type:EstateFeature) and EstateFeature has a property "MyFeatureValue". Note: These are the limited properties for the question. All Entities has an Id and all necesarry etc Estate IList<EstateFeature> EstateFeatures; EstateFeature FeatureValue MyFeat...

Implementing NHibernate DetachedCriteria-like

I would like to write something like DetachedCriteria but I don't want to use the ISession or Nhibernate at all... All I need is the implementations for ICriterion and Expression. after writing such Criteria -> I would like to generate an Xml Query or AD-Query or maybe even Query on collection (something like the Linq2Objects) Do you ...

Lazy loading not working for many-to-one relationship when mapping to a non-key field using property-ref

I have a legacy database that I am mapping using NHibernate. The objects of concern are an Account and a list of Notification objects. The objects look like: public class Notification { public virtual int Id { get; set; } public virtual DateTime BatchDate { get; set; } /* other properties */ public virtual Account Acco...

Order by collection count using ICriteria & NHibernate

Using the standard NHibernate example of Cats and Kittens, how would I use ICriteria to sort Cats based on Kitten count? For example, I want to do something like: ICriteria crit = Session.CreateCriteria(typeof(Cat)); return crit.Order(Order.Asc("**Kittens.Count**")); Anyone know how to achieve this? ...

Nhibernate ICriteria API Reference

Is there any good ICriteria API overview? Chapter 12 from the official NHibernate reference is too short and I still don't have clear view of the ICriteria usage. ...

NHibernate Projections and "Having" clause

I'm using NHibernate to query my database with the criteria API. My criteria is below: ICriteria c = Session.CreateCriteria(typeof(Transaction)); ProjectionList projections = Projections.ProjectionList(); projections.Add(Projections.Sum("Units"), "Units"); projections.Add(Projections.GroupProperty("Account"), "Account"); projections.Ad...

How to query for most commonly used many-to-one in nhibernate

I have the following issue in the project I am working on. Each transaction in the system is assigned to a given user. So there is a many to one relationship between transactions and users, like so: public class User { public int ID { get; private set; } public string FirstName { get; set; } .... } public class Transactio...

How do I select a Random Row using NHibernate's ICriteria API?

Can I select a random row using NHibernate's ICriteria API? ...

How am I supposed to query for a persisted object's property's subproperty in nhibernate?

I'm feeling dumb. public class Uber { public Foo Foo { get; set; } public Bar Bar { get; set; } } public class Foo { public string Name { get; set; } } ... var ubercharged = session.CreateCriteria(typeof(Uber)) .Add(Expression.Eq("Foo.Name", "somename")) .UniqueResult<Uber>(); return ubercharged; This throws a "could not r...

NHibernate - joining on a subquery using ICriteria

I have a SQL query that I need to represent using NHibernate's ICriteria API. SELECT u.Id as Id, u.Login as Login, u.FirstName as FirstName, u.LastName as LastName, gm.UserGroupId_FK as UserGroupId, inner.Data1, inner.Data2, inner.Data3 FROM dbo.User u inner join dbo.GroupMember gm on u.Id = ...

NHibernate ICriteria query with components and collections for advanced search

I'm building an advanced search form for my ASP.NET MVC app. I have a Customer object, with an Address Component: Fluent NHibernate mapping: public CustomerMap() { WithTable("Customers"); Id(x => x.Id) .WithUnsavedValue(0) .GeneratedBy.Identity(); Map(x => x.Name); Ma...

NHibernate - CreateCriteria vs CreateAlias

Hi, Assuming the following scenario: class Project{ public Job Job; } class Job{ public Name; } Assuming I want to use the Criteria API to search for all projects whose Job has the name "sumthing". I could use the CreateAlias to create an alias for Job and use it to access Name, or I could create a new Criteria for the proper...

Querying Overriding Entities Using a Self Join and the NHibernate Criteria API

I have a simple Waiver model, and I would like to make a query that returns all the Waivers that are not overridden. public class Waiver { private readonly int id; protected Waiver() { this.id = 0; } public virtual int Id { get { return id; } } public virtual string Name { get; set; } public virtua...

Iterating an NHibernate join

This is the first time I've used NHibernate for a big project so bear with me. Basically, I need to run a search based on 5 fields. I want to display the results in a table. Here is a test I've written that basically gets all Clients that have Intakes with a Staff named "DII". When I run it, I get an error saying that some of the I...

NHibernate passing parameter in criteria

I have an Ms Access view(query) as following select * from employee Where EmployeeId=SomeID Here SomeId is not a field name If I run this query from MsAccess It prompts me for entering value for SomeId as follows |---------------------------------------| | Enter Parameter Value X | |-----------------------------------...

How to use NHibernate ICriteria API to query by properties on a subclass of an associated object

Example: Client object has a collection of Action objects which records a history of actions performed against the client. Action is abstract and has several subclasses e.g. SystemAction, CorrespondenceAction etc. I have a client search screen which has many optional search criteria, so using the criteria API is the obvious choice. ...

nHibernate Criteria API Projections

I have an entity that is like this public class Customer { public Customer() { Addresses = new List<Address>(); } public int CustomerId { get; set; } public string Name { get; set; } public IList<Address> Addresses { get; set; } } And I am trying to query it using the Criteria API like this. ICriteria query = m_Custo...