queryover

NHibernate QueryOver association does not contain item

為{幸葍}努か 提交于 2019-12-04 12:27:39
could someone help me to translate LINQ expression to Nhibernate QueryOver from m in messages where !m.Recipients.Any(rcpt => rcpt.IsDeleted && rcpt.User = user) I tried this var qry = Session.QueryOver<UserMessage>(); qry.Where(m => m.Recipients.Any(r => !r.IsDeleted && r.User == user)); but got System.Exception : Unrecognised method call: System.Linq.Enumerable:Boolean Any[TSource](System.Collections.Generic.IEnumerable 1[TSource], System.Func 2[TSource,System.Boolean] !m.Recipients.Any(...) translates to a "not exists" sub-query. You will need a couple of aliases to correlate the sub-query

QueryOver API OrderBy using Case

不羁岁月 提交于 2019-12-04 03:41:24
How can I perform the following LINQ to NHibernate query using the QueryOver API. This gets a list of all records of Item from the DB and places Items with the status "Returned" to the end of the list. The status is an Enum which is mapped to a nvarchar in the database. var workList = session.Query<Item>() .OrderBy(i=> i.Status == Status.Returned ? 1 : 0) .ToList(); The SQL equivalent is SELECT * FROM Item ORDER BY case when Status='Returned' then 1 else 0 end I've of course tried var workList = session.QueryOver<Item>() .OrderBy(i => i.Status == Status.Returned ? 1 : 0).Asc .ToList(); But I

GROUP BY and HAVING clauses in nHibernate QueryOver

Deadly 提交于 2019-12-04 03:39:35
I'm trying to write this specific sql query in nHibernate QueryOver language, which I am not very familiar with: SELECT MessageThreadId FROM MessageThreadAccesses WHERE ProfileId IN (arr) GROUP BY MessageThreadId HAVING COUNT(MessageThreadId) = arr.Count where arr is a array of integers(user Ids) I'm passing as argument and MessageThreadAccess entity looks like this: public virtual MessageThread MessageThread { get; set; } public virtual Profile Profile { get; set; } .... After reading multiple stack overflow threads and experimenting I got this far with my query (trying to get MessageThread

NHibernate QueryOver: Get a row count with group by in a subquery

帅比萌擦擦* 提交于 2019-12-04 02:29:10
I'm trying to get a count from a query with a group by and just can't figure out how to translate the SQL I want into NHibernate's QueryOver syntax. This is the SQL: select count(*) from (select Email from Entry where (conditions...) group by Email) as tmp Seems simple right? This is how I'm trying to do it, but the RowCount() call seems to optimize the group by away completely: var query = _unitOfWork.CurrentSession.QueryOver<ContestEntry>() .Select(Projections.Property<ContestEntry>(x => x.Email), Projections.Group<ContestEntry>(x => x.Email)); return query.RowCount(); I wouldn't mind using

Using NHibernate QueryOver with a complex scenario

杀马特。学长 韩版系。学妹 提交于 2019-12-03 21:30:56
I´m trying to use QueryOver in that scenario : public class Class1 { public virtual string Name { get; set; } public virtual string Descripton { get; set; } public virtual Class2 { get; set; } public virtual IList<Class3> ListClass3{ get; set; } ... //SEVERAL OTHERS LISTS, PROPERTIES } public class Class2 { public virtual string Name { get; set; } ... //SEVERAL OTHERS LISTS, PROPERTIES } public class Class3 { public virtual string Name { get; set; } public virtual Class4 { get; set; } ... //SEVERAL OTHERS LISTS, PROPERTIES } public class Class4 { public virtual string Prop1 { get; set; }

Nhibernate count distinct (based on multiple columns)

杀马特。学长 韩版系。学妹 提交于 2019-12-03 18:10:00
问题 Basically, i have been trying to do this (count distinct based on two columns): select count(distinct(checksum(TableA.PropertyA, TableB.PropertyB))) from TableA left outer join TableB on TableA.TableBId = TableB.Id where PropertyA like '%123%' Been googling on how to do this but with no luck. Tried this, but never actually worked. This does not count distinctly based on the two properties from two tables: var queryOver = c.QueryOver<TableA>(); TableB tableBAlias = null; TableA tableAAlias =

nhibernate queryOver projection syntax

蹲街弑〆低调 提交于 2019-12-03 13:36:49
I am trying some code out from a NH 3.0 Cookbook, and wondering why I can't get the code below to compile. I think the QueryProjectionBuilder that should make this work is in "NHibernate.Criterion.Lambda" but the using directive for it doesn't help. The problems are the SelectGroup and SelectAvg parts. Assuming the syntax from the book is correct, can anyone see a missing reference here? namespace Queries.Implementations { using System; using System.Collections.Generic; using System.Linq; using Eg.Core; using NHibernate; using NHibernate.Criterion; using NHibernate.Criterion.Lambda; public

NHibernate 3. Alternatives to “ThenFetch” in QueryOver

ε祈祈猫儿з 提交于 2019-12-03 09:13:04
问题 I'm using NHibernate 3.0 with both the LINQ provider and QueryOver. Sometimes I want to eager load related data, and there comes the method "Fetch" to the rescue, both in LINQ and QueryOver. Now I have a special scenario where I want to eager load a property not directly on the second level, like: Foo f = ...; f.A.B.C with LINQ there's no problem, as you can "chain" fetches with the method "ThenFetch", like: var result = Session.Query<Foo>().Fetch(a => a.A).ThenFetch(b => b.B).ThenFetch(c =>

NHibernate QueryOver with MaxResult, Group By and Order By

倾然丶 夕夏残阳落幕 提交于 2019-12-03 07:11:46
问题 I'm trying to convert a SQL query to NHibernate QueryOver syntax, but I don't understand how to sort by the count projection. This is what the SQL Query looks like: select top 10 v.intVoteUserID, COUNT(v.intVoteUserID) from Group_MessageVotes v where v.dtmVote > :date group by v.intVoteUserID order by COUNT(v.intVoteUserID) desc Any ideas? 回答1: You can simply repeat the projection in the OrderBy-clause. The following query will give you an IList<object[]> where the first element of each item

Search text contains with QueryOver

冷暖自知 提交于 2019-12-03 06:56:11
问题 I'm trying to do this : var list = Session.QueryOver<Person>() .Where(x => x.LastName.Contains(searchText)) .List<Person>(); but I get this error : Unrecognised method call: System.String:Boolean Contains(System.String) Do you have an idea ? Update : public class Person { public virtual string FirstName { get; set; } public virtual string LastName { get; set; } } 回答1: NHibernate does not have direct C# equivalent as mentioned on this link http://nhibernate.info/blog/2009/12/17/queryover-in-nh