queryover

Join multiple tables with NHibernate and QueryOver

梦想的初衷 提交于 2019-12-05 13:27:36
I have this tables: Person -> PersonFavorites, PersonCompany PersonCompany -> Company I have now to do the following select with NHibernate and QueryOver: select * from Person inner join PersonFavorites on Person.Id = PersonFavorites.PersonId inner join PersonCompany on Person.Id = PersonCompany.PersonId inner join Company on Company.Id = PersonCompany.CompanyId where ... Can someone give me a sample, how I can do that? - My Problem is, that I have to join multiple Tables Person -> PersonCompany -> Company. The Join Person -> PersonCompany and Person -> PersonFavorites are no problem - but the

NHibernate QueryOver with sub-query and alias

我怕爱的太早我们不能终老 提交于 2019-12-05 11:46:40
I'm struggling to convert the following (simplified) HQL to QueryOver: select subscription from Subscription as subscription where not exists ( from Shipment as shipment where shipment.Subscription = subscription and (shipment.DeliveryDate = :deliveryDate) ) I've come this far: Subscription subscription = null; Session.QueryOver(() => subscription) .Where(Subqueries.NotExists(QueryOver.Of<Shipment>() .Where(shipment => shipment.Subscription == subscription) .And(shipment=> shipment.DeliveryDate == deliveryDate) .Select(shipment => shipment.Id).DetachedCriteria)); .TransformUsing(new

nhibernate queryover LIKE with expression trees

泄露秘密 提交于 2019-12-05 06:23:09
I'm looking to add a method to my base repository class that allows me to use LIKE expressions but I'm not quite sure of how to go about this. I want to create a generic method that looks at the expression tree passed in and looks for wildcard characters in the string values passed in. It would then generate the QueryOver statement accordingly. I have the following currently: public IList<T> FindAll(Expression<Func<T, bool>> criteria, char wildCard) { return SessionFactory.GetCurrentSession() .QueryOver<T>() .Where(criteria) .List(); } Obviously the hard part is yet to come. I need to look

NHibernate Eager Loading with Queryover API on a complex object graph

主宰稳场 提交于 2019-12-05 05:50:38
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> ids) { var daylogQuery = sess.QueryOver<Daylog>() .WhereRestrictionOn(dl => dl.DaylogID).IsIn(ids

nhibernate queryOver projection syntax

假装没事ソ 提交于 2019-12-04 21:21:48
问题 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;

nhibernate - queryover - how to make dynamic sorting for joined queries

不问归期 提交于 2019-12-04 15:24:18
I have a user accounts table in admin panel and this table holds data from different db tables (tables in SQL database ). And user accounts table has to support paging and sorting. When I try to sort data with "FirstName" fetched from Account db table , .net throw an exception saying Location db table does not have "FirstName" column. My method is like: Account acc = null; //bunu bu şekilde tanımlamadan olmuyor :S AccountLogin accl = null; //bunu bu şekilde tanımlamadan olmuyor :S Program prog = null; Location school = null; Location town = null; Location city = null; //Takip edilen bloggerın

Select or SelectList: I Want to include the entire entity

僤鯓⒐⒋嵵緔 提交于 2019-12-04 15:21:15
I am querying a list of objects, and then correlating them with a subquery. I want to return the results of the subquery, as well as the root entity. But I can't figure out how to actually return the root entity, I can only return individual properties of it. Specifically, this works: this.Session.QueryOver<MediaFile>(() => mediaFile) .SelectList(list => list.Select(mf => mf.Id)); But this does not: this.Session.QueryOver<MediaFile>(() => mediaFile) .SelectList(list => list.Select(mf => mf)); I get the following error: Could not resolve property : of MediaFile Does anyone know how I can

Fluent Nhibernate Composite Key Not Generating Joins For Referenced Entities

依然范特西╮ 提交于 2019-12-04 15:08:26
I have a mapping with a composite key as below: CompositeId() .KeyReference(x => x.CreatedBy, "member_key") .KeyReference(x => x.Box, "box_key"); This works fine for simple gets and inserts, however it is not generating joins with the tables mentioned in the reference where I try and use them as part of a query. So this: return _sessionFactory.GetCurrentSession().QueryOver<BoxMember>() .Where(x => x.Box.Id == boxId) .Where(x => x.Member.DeletedDate == null) .Fetch(x => x.Box).Eager .Fetch(x => x.CreatedBy).Eager .List(); Generates the following SQL: SELECT this_.member_key as member1_5_0_,

Using current_timestamp in NHibernate QueryOver syntax

让人想犯罪 __ 提交于 2019-12-04 14:45:41
Is it possible to request the usage of current_timestamp in any other nhibernate query methods except for SQL and HQL? I was thinking of making some type of IUserType class of DbDateTime or something in order to solve the problem, but wouldn't know exactly how to accomplish it. Anyone have any ideas? example of what I want: session.QueryOver<User>() .Where(u => u.CreatedOn > current_timestamp) .List(); You can use IProjection and SQL functions in the QueryOver API like this: var result = session.QueryOver<User>() .Where(Restrictions.GtProperty( Projections.Property<User>(u => u.CreatedOn),

NHibernate - filtering out results based on child-property

谁说胖子不能爱 提交于 2019-12-04 12:28:28
I have this code fetching all enabled Groups with their children. The problem I have is that the children can also be disabled but I can't get fluent nhibernate to only fetch groups where all childrens are enabled. I assume this is possible but how? public class Group { public bool IsDisabled { get; set; } public string Description { get; set; } public ICollection<ChildType> Children { get; protected set; } } public class ChildType { public bool IsDisabled { get; set; } public string Description { get; set; } } public IList<Group> Search(string searchString) { IQueryOver<Group> query = Session