queryover

NHibernate lazy loading nested collections with futures to avoid N+1 problem

戏子无情 提交于 2019-11-27 12:38:45
问题 I have an object model that looks like this (pseudo code): class Product { public ISet<Product> Recommendations {get; set;} public ISet<Product> Recommenders {get; set;} public ISet<Image> Images {get; set; } } When I load a given product and want to display the images of its recommendations, I run into an N+1 problem. (The recommendations are lazy-loaded, then a loop calls the .Images property of each one.) Product -> Recommendations -> Images What I want to do is eagerly load this

What is the difference between JoinQueryOver and JoinAlias?

社会主义新天地 提交于 2019-11-27 11:16:30
I need to know what is the difference between JoinQueryOver and JoinAlias, and when to use each? thanks. Vadim 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.info/doc/nh/en/index.html#queryqueryover ) IQueryOver<Cat,Kitten> catQuery = session.QueryOver<Cat>()

Eagerly fetch multiple collection properties (using QueryOver/Linq)?

老子叫甜甜 提交于 2019-11-27 10:46:30
问题 I found 2 similar questions: Multiple Fetches in linq to nhibernate Is this the right way of using ThenFetch() to load multiple collections? According to this page: Be careful not to eagerly fetch multiple collection properties at the same time. Although this statement will work fine: var employees = session.Query<Employee>() .Fetch(e => e.Subordinates) .Fetch(e => e.Orders).ToList(); It executes a Cartesian product query against the database, so the total number of rows returned will be the

NHibernate: Select item with entry in element bag

六眼飞鱼酱① 提交于 2019-11-27 08:36:41
问题 I have a class with property of list. public class Paperboy{ private int _id; private string _lastname; private string _firstname; private string _mobile; private string _phone; private IList<string> _additionalPhoneNumbers; } The List is mapped as bag with key and element. <class name="Paperboy" table="tblPaperboy" lazy="false"> <id name="_id" column="Id" access="field" > <generator class="assigned"/> </id> <property name ="_lastname" column="Lastname" access ="field" /> <property name ="

Preventing multiple instance after inner join

 ̄綄美尐妖づ 提交于 2019-11-27 08:19:50
问题 I have a small problem with multiple instances of the same object after a join to an other table. For testing I create one Store with two Products (ManyToMany-Relation). The following snippet hopefully describes my problem. var preResult = _session.QueryOver<Store>().List(); // One store Product productAlias = null; var result = _session.QueryOver<Store>() .JoinAlias(s => s.Products, () => productAlias) .List(); // Two instances of the same store I even think this behavior is correct but how

NHibernate Fetch/FetchMany duplication in resultset, how to fix with ToFuture()

一个人想着一个人 提交于 2019-11-27 04:51:50
问题 I'm relatively new to using NHibernate and I'm running into a shortcoming I can't seem to work myself around. I have an object tree that I wish to retrieve from the database in a single roundtrip but end up with a cartesian product. The objects I'm trying to retrieve are called 'AccountGroup' , 'Concern' , 'Advertiser' and 'Product' and I only wish to get those objects where the active user has permissions for. My initial query looked like this: using (var session = OpenSession()) { return

NHibernate QueryOver how to join on non declared relationship

巧了我就是萌 提交于 2019-11-27 03:41:53
问题 How to do the following join to return Users who have access to a Company given a company id. The problem is there is no explicit relationship using a User object between UserAccess and User they simply join on the string property Username: User(Username, Name) UserAccess(Username, Company) Company(Id) Session.QueryOver<Company>() .Where(c => c.Id == companyId) .JoinQueryOver<UserCompanyAccess>(u => u.UserAccessList) .JoinQueryOver<User>(u => **Nope no property, just a string** 回答1: could be

ToRowCountQuery seems to ignore groupings

梦想与她 提交于 2019-11-26 23:37:27
问题 I'm trying to create a rowcount-query from a regular query, but the resulting SQL seems to lack the GROUP BY resulting in a wrong count. Does anyone know what I'm doing wrong. First the queries: var query = Session.QueryOver<InkoopFactuurListItem>() .Where(i => i.KlantId == Klant.Id) .AndRestrictionOn(i => i.Status).IsIn(statussen) .SelectList(list => list .SelectGroup(h => h.Id).WithAlias(() => dto.Id) .SelectGroup(h => h.Banknummer).WithAlias(() => dto.Banknummer) .SelectGroup(h => h

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

不想你离开。 提交于 2019-11-26 23:19:15
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 noter = _repo.QueryOver().Where(n => n.JournalNr == journalNr).Fetch(x => x.Noter).Eager.Future<Sag>(); var

NHibernate QueryOver group by without selecting the grouped by column

穿精又带淫゛_ 提交于 2019-11-26 21:39:37
问题 Having a query like the following: var subquery = SessionFactory.GetCurrentSession() .QueryOver<SomeEntity>() .Where(_ => _.SomeOtherEntity.Id == someId) .SelectList(list => list .SelectGroup(x => x.SomeGroupByProperty) .SelectMax(x => x.MaxPerGroupProperty)) .List<dynamic>(); The generated sql is selecting both SomeGroupByProperty and maximum of MaxPerGroupProperty . Is it possible to get it to group on SomeGroupByProperty but only select maximum of MaxPerGroupProperty ? This is for using