queryover

Join Unrelated tables in Fluent Nhibernate with QueryOver or CreateCriteria

拈花ヽ惹草 提交于 2019-12-02 09:14:23
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, tableMiscDetails.clientType, tableMiscDetails.clientName, tableMiscDetails.MarketValueAmount from

NH QueryOver - use properties of main query in subquery

末鹿安然 提交于 2019-12-02 06:23:16
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 query as a subquery which I want to connect to the main query. The problem is that the table aliased as R

Project Collection in NHibernate

删除回忆录丶 提交于 2019-12-02 06:05:39
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(); Radim Köhler We have to thing about projection as a single SELECT clause. What we would be able to do with it on a DB side, we can mimic with

Nhibernate Linq query to QueryOver

∥☆過路亽.° 提交于 2019-12-02 05:01:39
I have the following piece of code: 1: ids = GetAnArrayOfIds(); 2: jobEntities = jobEntities.Where(j => j.Locations.Select(l => l.Id).Any(ids.Contains)); How do I write 2 using QueryOver ? Thank you, var results = session.QueryOver<Job>() .JoinQueryOver<Location>(u => u.Locations) .Where(loc => loc.Id.IsIn(ids)) .TransformUsing(Transformers.DistinctRootEntity) .List(); Hope this helps 来源: https://stackoverflow.com/questions/6997146/nhibernate-linq-query-to-queryover

NHibernate QueryOver projection on many-to-one

陌路散爱 提交于 2019-12-02 04:34:46
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 different creators, 6 queries will be run 1 for the list of posts and 5 for the creators. I tried to get it

QueryOver: select columns from subquery

不羁的心 提交于 2019-12-02 03:25:46
问题 How can I select / project values from a subquery from a different table into my main query? I have an NH-model like this: [Serializable] public class MyModel { public virtual int Id {get; set;} //more mapped values .... //unmapped values public virtual string ValueFromOtherTable {get;set;} } And I want to fill ValueFromOtherTable with a left join like this: Select mt.*, ..., ot.ValueFromOtherTable from MyModelTable mt left join OtherTable ot ON (somecondition) where MyModelTable is the table

NHibernate : QueryOver in generic method

て烟熏妆下的殇ゞ 提交于 2019-12-02 02:59:50
问题 I have this test method, I have a problem on the "List" method. I'd like use several class (all inplement IAdminDecimal). On the QueryOver, I have this error : The type 'T' must be a reference type in order to use it as parameter 'T' in the generic type or method 'NHibernate.ISession.QueryOver()' using (var session = sessions.OpenSession()) { using (var tx = session.BeginTransaction()) { CurrentSessionContext.Bind(session); AdministrationService service = new AdministrationService(session);

QueryOver: select columns from subquery

99封情书 提交于 2019-12-02 01:41:47
How can I select / project values from a subquery from a different table into my main query? I have an NH-model like this: [Serializable] public class MyModel { public virtual int Id {get; set;} //more mapped values .... //unmapped values public virtual string ValueFromOtherTable {get;set;} } And I want to fill ValueFromOtherTable with a left join like this: Select mt.*, ..., ot.ValueFromOtherTable from MyModelTable mt left join OtherTable ot ON (somecondition) where MyModelTable is the table mapped to MyModel-class. I want to fill ValueFromOtherTable (no NH-mapping) by selecting all values

NHibernate : QueryOver in generic method

早过忘川 提交于 2019-12-01 22:51:46
I have this test method, I have a problem on the "List" method. I'd like use several class (all inplement IAdminDecimal). On the QueryOver, I have this error : The type 'T' must be a reference type in order to use it as parameter 'T' in the generic type or method 'NHibernate.ISession.QueryOver()' using (var session = sessions.OpenSession()) { using (var tx = session.BeginTransaction()) { CurrentSessionContext.Bind(session); AdministrationService service = new AdministrationService(session); service.List<AdminDelay>(); tx.Commit(); } } The class : public class AdministrationService { private

Order by relation count in NHibernate

烂漫一生 提交于 2019-12-01 14:58:37
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 and not in memory on the webserver. var loadedUser = session.Query<User>() .Select(u => new { u, u.Books