queryover

Help with QueryOver and WhereExists

允我心安 提交于 2019-12-03 06:36:19
I have a problem. I have Persons and Cats. Each Person has some Cats (there is a foreign key in Cats that points to the primary key in Persons). Each Cat has an Age. I want to select the Persons that have "Old" Cats. I want ALL the Cats of these persons, and not only the "Old" Cats. I need to do it with the QueryOver syntax. In T-SQL it would be something like: SELECT P.*, C.* FROM Persons P LEFT JOIN Cats C ON P.Id = C.OwnerId WHERE EXISTS ( SELECT 1 FROM Cats C2 WHERE P.Id = C2.OwnerId AND C2.Age > 5) I know I have to use the subqueries, and I could to easily with the "old" nhibernate syntax

How to do subqueries in nhibernate?

夙愿已清 提交于 2019-12-03 02:10:34
I need to do a subquery on a sub collection but I can't get it to work. I tried this Task tAlias = null; List<Task> result = session.QueryOver<Task>(() => tAlias) .Where(Restrictions.In(Projections.Property(() => tAlias.Course.Id), courseIds)) .WithSubquery.WhereExists(QueryOver.Of<CompletedTask>().Where(x => x.Student.StudentId == settings.StudentId)) ().ToList(); Yet I get Cannot use subqueries on a criteria without a projection. dotjoe session.QueryOver<Task>(() => tAlias) .WhereRestrictionsOn(x => x.Course.Id).IsIn(courseIds) .WithSubquery.WhereExists(QueryOver.Of<CompletedTask>() .Where(x

NHibernate 3. Alternatives to “ThenFetch” in QueryOver

ぐ巨炮叔叔 提交于 2019-12-02 23:24:15
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 => c.C).ToList(); In QueryOver there's no such method, so how can I achieve the same result? Thanks in

Join Unrelated tables in Fluent Nhibernate with QueryOver or CreateCriteria

可紊 提交于 2019-12-02 23:03:11
问题 I have tables : tableAnnual - AnnualAmount, AnnualCurrency. creationDate, Id tableMonthly - MonthlyAmount, MonthlyCurrency, creationDate, Id tableSharevalue - CurrentSharevalue, creationDate, Id tableMiscDetails - clientType, clientName, MarketValueAmount, creationDate I have now to do the following select with NHibernate and QueryOver: Select tableAnnual.AnnualAmount, tableAnnual.AnnualCurrency, tableMonthly.MonthlyAmount, MonthlyAmount.MonthlyCurrency, tableSharevalue.CurrentSharevalue,

Search text contains with QueryOver

混江龙づ霸主 提交于 2019-12-02 21:35:55
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; } } HatSoft NHibernate does not have direct C# equivalent as mentioned on this link http://nhibernate.info/blog/2009/12/17/queryover-in-nh-3-0.html Additional Restrictions Some SQL operators/functions do not have a direct equivalent in C#

How do I get row count using the NHibernate QueryOver api?

前提是你 提交于 2019-12-02 21:10:16
I'm using the QueryOver api that is part of NHibernate 3.x. I would like to get a row count, but the method I'm using returns all objects and then gets the count of the collection. Is there a way to just return an integer/long value of the number of rows? I'm currently using: _session.QueryOver<MyObject>().Future().Count() Jim Geurts After a bit of playing around with the api, this will do it: _session.QueryOver<MyObject>() .Select(Projections.RowCount()) .FutureValue<int>() .Value If you don't want to return it as a future, you can just get the SingleOrDefault<int>() instead. Another method

NHibernate QueryOver projection on many-to-one

泪湿孤枕 提交于 2019-12-02 13:38:18
问题 I am trying to get a QueryOver working using a Projection on a many-to-one . The class "Post" has a property many-to-one "Creator". Using session.QueryOver(Of Post). Select(Projections. Property(of Post)(Function(x) x.Creator). WithAlias(Function() postAlias.Creator)). TransformUsing(Transformers.AliasToBean(Of Post)()). List() works BUT each creator is retrieved by a single query rather than using a join like it is done when not using a select/projection. So if there are 5 posts with 5

What can be used as a NHibernate QueryOver alias?

做~自己de王妃 提交于 2019-12-02 12:19:50
问题 I know so far that a local variable or a local property can be used as an alias like so ClassA _aliasA; _session.QueryOver(x => x.ClassA, () => _aliasA); or ClassA AliasA { get; set; } _session.QueryOver(x => x.ClassA, () => AliasA); I want to know what other options are possible. Like, are properties of an external class a valid option? class ClassGenericAliases { ClassA Class { get; set; } } _session.QueryOver(x => x.ClassA, () => ClassGenericAliases.ClassA); Can statics be used as aliases?

fetching strategies for collections of abstract type

杀马特。学长 韩版系。学妹 提交于 2019-12-02 11:51:39
so here's the situation: suppose I have a class structure used to represent flexible search: public class SearchDefinition { public virtual string Name {get; set;} public virtual IEnumerable<SearchTerm> Terms {get; set;} } public abstract class SearchTerm { public virtual Operator Op {get; set; } //i.e 'In', 'Not in', 'Contains' etc.. public abstract IEnumerable<object> CompareValues {get; } //the values against which the search is performed. for example- 'in (2,6,4)', 'contains ('foo', 'blah')'. } now, since search terms can refer to different fields, each type of term has its own class:

Project Collection in NHibernate

落爺英雄遲暮 提交于 2019-12-02 11:06:28
问题 Is it possible that I can project collection in NHibernate? For Example: User { UserGuid, IList<Groups> UserGroups, } User userEntity = null; _session .StatefulSession.QueryOver(() => userEntity) .SelectList(list => list .Select(x => x.UserGuid).WithAlias(() => userEntity.UserGuid) //How can I project group collection here? .Select(x => x.Groups).WithAlias(() => userEntity.Groups) ) .TransformUsing(Transformers.AliasToBean<UserEntity>()) .List(); 回答1: We have to thing about projection as a