queryover

Am I doing something wrong with Nhibernate Query Over fetch?

限于喜欢 提交于 2019-12-22 10:23:44
问题 I have this using (ITransaction transaction = session.BeginTransaction()) { Task tAlias = null; CompletedTask cAlias = null; List<Task> tasks = session.QueryOver<Task>(() => tAlias) .Where(Restrictions.In(Projections.Property(() => tAlias.Course.Id), courseIds)) .Fetch(pt => pt.PersonalTaskReminders).Eager .List<Task>().ToList().ConvertToLocalTime(student); transaction.Commit(); return tasks; } PersonalTaskReminders == Collection So a task can have many personalTaskReminders. I am finding

NHibernate QueryOver - Retrieve all, and mark the ones already “selected”

喜你入骨 提交于 2019-12-22 08:55:35
问题 Dear NHibernate experts, The following query gives me all my categories: var result = Session.QueryOver(() => cat).List(); .. and by running this query, I get the ones selected (category_x_product table): int productId = 11; Category cat = null; CategoryProduct cp = null; var subQuery = QueryOver.Of(() => cp) .Where(() => cp.ProductId == productId) .Select(Projections.Distinct(Projections.Property(() => cp.CategoryId))); result = Session.QueryOver(() => cat) .WithSubquery .WhereProperty(() =>

NHibernate Eager Loading with Queryover API on a complex object graph

蓝咒 提交于 2019-12-22 05:09:09
问题 I've got a pretty complex object graph that I want to load in one fell swoop. Samples have Daylogs which have Daylog Tests which have Daylog Results Daylog Tests have Testkeys, Daylog Results have Resultkeys, and TestKeys have Resultkeys. I'm using the QueryOver API and Future to run these all as one query, and all the data that NHibernate should need to instantiate the entire graph IS being returned, verfied by NHProf. public static IList<Daylog> DatablockLoad(Isession sess, ICollection<int>

Where … In … Or Where … In … with NHibernate IQueryOver

余生长醉 提交于 2019-12-21 09:26:52
问题 I'm trying to emulate subject query with NHibernate's IQueryOver . So far I have var q = CurrentSession.QueryOver<ObjectModel.Order>(). WhereRestrictionOn(o => o.Buyer.ID).IsIn(partyIDs). WhereRestrictionOn(o => o.Seller.ID).IsIn(partyIDs); This, however, generates an and query, whereas I need to have an or operator between two where clauses. How is this done with IQueryOver ? 回答1: As it usually is, found question soon after explaining the problem to general public. Thanks, guys! var q =

Help with QueryOver and WhereExists

送分小仙女□ 提交于 2019-12-20 20:19:09
问题 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

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

元气小坏坏 提交于 2019-12-20 09:59:19
问题 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() 回答1: 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

fetching strategies for collections of abstract type

爷,独闯天下 提交于 2019-12-20 06:28:08
问题 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

How to eager load objects in a list/collection?

江枫思渺然 提交于 2019-12-20 04:16:37
问题 I have the following query: ObjectB objectBAlias = null; ObjectC objectCAlias = null; var query = session.QueryOver<ObjectA>(); var results = query .JoinAlias(x => x.listOfBs, () => objectBAlias) .JoinAlias(x => objectBAlias.ObjectC, () => objectCAlias) .TransformUsing(new DistinctRootEntityResultTransformer()) .List<ObjectA>(); class ObjectA { IList<ObjectB> listOfBs; } class ObjectB { ObjectA a; ObjectC c; } class ObjectC { int x; } ObjectA has a many-to-many relationship to ObjectC with

NH QueryOver - use properties of main query in subquery

孤街浪徒 提交于 2019-12-20 03:51:08
问题 I am trying to convert following SQL to QueryOver: Select 1 From myTable mt Where mt.ForeignKey in (select ID from otherTable ot where ot.ID = R.ID) I want to use this subquery inside an EXISTS / NOT EXISTS statement like: select * from table R where .... AND EXISTS (query above) Currently I have something like: mainQuery.WithSubquery.WhereExists(QueryOver.Of<myTable>() .Where(mt => mt.ForeignKey) .WithSubquery.IsIn(QueryOver.Of<otherTable>().Where(c => c.Id == R.SomeId))); I created this

Order by relation count in NHibernate

有些话、适合烂在心里 提交于 2019-12-19 12:12:33
问题 I have a datastructure like this: public class User { public Guid Id {get;set;} public string Name {get;set;} public IList<Books> Books {get;set} } I have been struggeling with making it possible to sort the users by the count of bookmarks (one-to-many relation). I have tried various approaches with both linq, criteria and queryover, but with no luck, and therefore hope one of you could help. I am using paging, since I have quite a few users, so the solution needs to do the query on the SQL