icriteria

NHibernate correlated subquery using ICriteria

做~自己de王妃 提交于 2019-12-06 10:48:33
问题 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 INT, BirthDate DATETIME ) CREATE TABLE PersonDetails ( PersonNo INT, FirstName VARCHAR(30), Surname VARCHAR(30) ) And the query... SELECT P.PersonNo, P.FirstName, P.Surname

NHLambdaExtensions: Create a Criterion object to add to ICriteria later

為{幸葍}努か 提交于 2019-12-06 10:28:55
My application creates a dynamically generated query at runtime based on user input by creating Criterion objects e.g: ICriterion criterion = Restrictions.Eq("Name", "John"); ...... detachedCriteriaSomewhereElse.Add(criterion); How do I do this in NHLambdaExtensions? what I really need to do is ICriterion criterion = Restrictions.Eq<Person>(p=> p.Name == "John"); but this isn't valid. Is there any way to do this? With the NHLambdaExtensions you have the SQLExpression class that lets you do the following: ICriterion criterion = SqlExpression.CriterionFor<Person>(p => p.Name == "John"); 来源:

NHibernate - Implement “NOT IN” query using ICriteria

时光怂恿深爱的人放手 提交于 2019-12-05 21:32:52
问题 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 WHERE ProductId NOT IN (1,5,9,23,45) How do I do this in NHibernate using either ICriteria or HQL (but preferably ICriteria)? 回答1: Try .Add(Expression.Not

NHibernate: Convert an ICriteria to a DetachedCriteria

最后都变了- 提交于 2019-12-05 19:40:37
Anyone know how to convert an ICriteria into a DetachedCriteria. I need to use an existing ICriteria as part of a subquery using: .Add(Subqueries.PropertyIn("Name", myDetachedCriteriaSubquery)) Is there any way to convert an ICriteria to a DetachedCriteria. I will accept 'no' with a credible reference. Following on from mattk's answer, you can inherit DetachedCriteria to access its constructors: public class ConvertedDetachedCriteria : DetachedCriteria { public ConvertedDetachedCriteria(ICriteria criteria) : base((CriteriaImpl) criteria, criteria) { var impl = (CriteriaImpl) criteria; impl

Removing Order from NHibernate Criteria Query

情到浓时终转凉″ 提交于 2019-12-05 18:37:05
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.GetSession.CreateCriteria<Person>.AddOrder("OrderProperty", Order.Desc); } public ICriteria CountQuery { get{ return StandardQuery.SetProjection(Projections.Count("ID")); } Obviously the CountQuery barfs with "Column "dbo.Person.ordercolumn" is invalid in the ORDER BY clause

NHibernate Projections and “Having” clause

社会主义新天地 提交于 2019-12-05 11:41:11
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.Add(Projections.GroupProperty("Security"), "Security"); c.SetProjection(projections); This is working fine, but what I would like is a way to be able to limit the query to only return when the "Units" property is > 0. In SQL I would simply us a Having Units > 0

NHibernate Lambda Extensions - Eager Loading a collection's assosciations

青春壹個敷衍的年華 提交于 2019-12-04 21:06:17
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 Person person inner join person.Friends friends inner join fetch friends.MainProfileImage image inner join fetch image.MediumThumbnail where person = :person1 order by friends.LatestLogin desc Here's My Criteria effort. For some reason this doesn't return anything!

NHibernate Query across multiple tables

蓝咒 提交于 2019-12-04 19:58:29
问题 I am using NHibernate, and am trying to figure out how to write a query, that searchs all the names of my entities, and lists the results. As a simple example, I have the following objects; public class Cat { public string name {get; set;} } public class Dog { public string name {get; set;} } public class Owner { public string firstname {get; set;} public string lastname {get; set;} } Eventaully I want to create a query , say for example, which and returns all the pet owners with an name

Nhibernate ICriteria and Using Lambda Expressions in queries

风流意气都作罢 提交于 2019-12-04 17:21:12
hi i am new in NHibernate and i am a little confused. Suppose we have a product table. Let the product table have 2 columns price1 and price2. then i may query mapped product entities via HQL as follows: string queryString = @"from product p where p.price1 = p.price2 + 100 "; IList result = session.CreateQuery(queryString).List(); How can i achieve that via ICriteria API. i know it's absurd but i am trying sth like that: session.CreateCriteria(typeof(product)) .Add(Expression.Eq("price1", "price2" + 100)) .List() or more appropriately sth like that (using lambda extensions): session

NHibernate Query across multiple tables

半世苍凉 提交于 2019-12-03 12:47:21
I am using NHibernate, and am trying to figure out how to write a query, that searchs all the names of my entities, and lists the results. As a simple example, I have the following objects; public class Cat { public string name {get; set;} } public class Dog { public string name {get; set;} } public class Owner { public string firstname {get; set;} public string lastname {get; set;} } Eventaully I want to create a query , say for example, which and returns all the pet owners with an name containing "ted", OR pets with a name containing "ted". Here is an example of the SQL I want to execute: