queryover

queryover and (x like 'a' or y like 'a')

℡╲_俬逩灬. 提交于 2019-11-26 19:14:13
问题 Hi Is there any elegant way of combining 'like' and 'or' when i'm using queryover API? for 'like' there is something like: query.WhereRestrictionOn(x=>x.Code).IsLike(codePart) for 'or' i can do something like: query.Where( x=>x.Code == codePart || x.Description== codePart) but how can I create a query like this: select * from n where code like '%abc%' or description like '%abc%' 回答1: query.Where(Restrictions.On<Type>(x => x.Code).IsLike(codePart) || Restrictions.On<Type>(x => x.Description)

How to join Two tables of two non relashinship defined columns using Nhibernate QueryOver

这一生的挚爱 提交于 2019-11-26 18:38:59
问题 Using NHibernate QueryOver , I want to join two tables using two columns which are not defined in the mapping as a relationship. E.g. This is not my exact scenario but this can explain that Tables: Employee(Id, Name, DepartmentId, SomeCode,Address) Department (Id, Name, ,Code) Select SELECT * FROM EMPLOYEE E JOIN DEPARTMENT D ON D.Code = E.SomeCode Can someone please tell me how to do this query using NHibernate QueryOver . Note that "SomeCode" in Employee and "Code" in Department are not

What is the difference between JoinQueryOver and JoinAlias?

落爺英雄遲暮 提交于 2019-11-26 15:27:01
问题 I need to know what is the difference between JoinQueryOver and JoinAlias, and when to use each? thanks. 回答1: Functionally they do the same thing, create a join to another entity. The only difference is what they return. JoinQueryOver returns a new QueryOver with with the current entity being the entity joined, while JoinAlias returns the original QueryOver that has the current entity as the original root entity. Whichever one you use is a matter of personal taste: (from http://nhibernate

Is this the right way to eager load child collections in NHibernate

杀马特。学长 韩版系。学妹 提交于 2019-11-26 08:37:47
问题 I have used too much time to find a nice way to eager load child collections. so far this is what I got. It\'s working but I find it hard to believe that this is the best way to write this query [Fact] public void EagerLoadQueryOverWithFutureTest() { const long journalNr = 1470; var query = _repo.QueryOver().Where(s => s.JournalNr == journalNr).Future<Sag>(); var sagsansoegning = _repo.QueryOver().Where(an => an.JournalNr == journalNr).Fetch(x => x.Sagsansoegning).Eager.Future<Sag>(); var

NHibernate QueryOver with Fetch resulting multiple sql queries and db hits

眉间皱痕 提交于 2019-11-26 03:46:00
问题 I\'m trying to select an entity and fetch a related list: Session.QueryOver<UserRole>() .Fetch(x => x.UsersInRole).Eager .List(); Which results in a lot of database hits. The first one is something like: SELECT ... FROM UserRoles left outer join UsersInRoles on ... And hundreds more seperate queries which looks something like: SELECT ... FROM UsersInRoles left outer join UserRoles on ... WHERE UserRoles.UserId=? The mapping is as following: public class UserRoleMap : ClassMap<UserRole> {