queryover

nhibernate: select parents and newest child

故事扮演 提交于 2019-12-11 06:43:34
问题 I have the following entities public class Vehicle { public virtual string InternalNumber { get; set; } public virtual IList<VehicleDriverHistory> DriverHistory { get; set; } } public class VehicleDriverHistory : HistoryEntity { public virtual Vehicle Vehicle { get; set; } public virtual DriverPerson Driver { get; set; } public virtual DateTime Date { get; set; } } Now I need to select every Vehicle and, if present, the newest VehicleDriverHistory-Entry according to "Date". But I'm kinda

NHibernate / QueryOver: How to left join with parameter

大憨熊 提交于 2019-12-11 06:30:15
问题 Is there a way in NHibernate / QueryOver API to pass a parameter already in the mapping (so it uses the parameter as a fixed value for all queries on this particular instance). I need this (or a workaround) because I have a view like this in the Database: CREATE VIEW ProblematicView AS SELECT v.*, -- lots of data FROM someView v LEFT JOIN someTable t ON v.ForeignKey = t.ForeignKey Now additionally to the ForeignKey match I need an additional check for a property like this: AND t

NHibernate QueryOver the values of a dictionary(map)

白昼怎懂夜的黑 提交于 2019-12-11 06:28:56
问题 For a project i'm working on, i need to query over the values of a mapped dictionary in Nhibernate. Something like SELECT * FROM EntityWithDictionary WHERE EntityWithDictionary in (select EntityFromDictionaryId FROM Dictionary where value = 'testvalue') I've tried several things but I can't figure out how i can do it. Here is what i have. Entity public class EntityWithDictionary { public virtual Guid Id { get; set; } public virtual string Description { get; set; } private IDictionary<string,

Equals conditions in outer joins with NHibernate ICriteria/QueryOver query

走远了吗. 提交于 2019-12-11 03:02:33
问题 How do I do a equals condition in an outer join in Nhibernate/QueryOver/ICriteria? The only way I have found to compare surveyRequest.Survey.Id with surveyID below is with IsIn . SystemUser systemUser= null; SurveyRequests surveyRequest = null; var query = Session.QueryOver<SystemUser>(() => systemUser) .Left.JoinAlias( () => systemUser.SurveyRequests, () => surveyRequest, Restrictions.On(()=>surveyRequest.Survey.Id).IsIn(new object []{surveyID })) // ^^^^ (I am reusing an earlier query

NHibernate QueryOver

亡梦爱人 提交于 2019-12-11 02:54:57
问题 I've searched around but not found what I am doing wrong here. I have object C which holds a list of object L, object C also holds a reference to class R. From object L I want to find object R. I'm trying to do this but I only get null using this code: L is already an instanced object a function receives. var t = SessionController.CurrentSession.QueryOver<C>() .Where(c => c.Id == L.C_Id) .JoinQueryOver<R>(c => c.R) .Select(c => c.R).SingleOrDefault(); Any idea what I'm doing wrong here would

QueryOver IList<string> property

感情迁移 提交于 2019-12-11 02:54:13
问题 I have a mapped class that has a ICollection property which is mapped as a Set (using by code mappings). Note that the collection contains strings and not another mapped entity. e.g. public class Item { public virtual ICollection<string> Facts { get; set; } } public class ItemMapping { public ItemMapping() { Set(x => x.Facts, m => { m.Key(k => k.Column("ItemId")); m.Table("Facts"); }, col => col.Element(m => { m.Column("Description"); m.Type(NHibernateUtil.String); })); } } This works and

Fluent Nhibernate - selecting specific column and count query with group by

安稳与你 提交于 2019-12-10 21:08:09
问题 I'm having some trouble excuting a query in fluent nhibernate. I have a table : Books with the following columns: ID, NAME, YEAR, BOOK_TYPE, AUTHOR_ID I want to excute the following sql query in Fluent NHibernate: SELECT BOOK_TYPE, COUNT(*) FROM BOOKS GROUP BY BOOK_TYPE 回答1: So called Fluent-NHibernate is just a mapping extension. To get data we need NHibernate built n querying features: ICriteria , QueryOver or even a LINQ . Based on the documentation we can use projections for the above

NHibernate count another entity with sub query?

房东的猫 提交于 2019-12-10 19:27:18
问题 I have two entities which are: User { UserGuid, Address, . . . EmailCount // This is not a column in the database, // I just wanna get the count number from the UserEmail table // and map the value to this property } UserEmail { UserGuid, Timestamp } The issue is how can I get the email count with a sub query in NHibernate? By far I have this, but it does not work. Any idea? User userEntity = null; var subQuery = QueryOver.Of<UserEmail>() .Where(ue => ue.UserGuid == userEntity.UserGuid)

Adding more than one condition in Projection.Conditionals for queryover

浪子不回头ぞ 提交于 2019-12-10 18:06:48
问题 I am trying to write a case with more than one when clause; something like this: ... case when 'starks' then 1 when 'wildlings' then 2 when 'lannisters' then 3 Else 0 End ... I've done a single conditional before with something like .OrderBy(Projections.Conditional( Restrictions.Where<House>(r => r.Name.IsLike("starks")), Projections.Constant(0), Projections.Constant(1))).Asc(); But I can't figure out how to add an extra condition / when clause in there :/ I've tried adding an extra outer

Filtering and projecting an association using NHibernate QueryOver

假如想象 提交于 2019-12-10 17:47:25
问题 Suppose you have an entity similar to this: public class Mailinglist { public virtual Guid Id { get; set; } public virtual ICollection<Subscriber> Subscribers { get; set; } } The NHibernate mapping for the entity is as you would expect: Id is the identifier and Subscribers is mapped with <set> and <many-to-many> referincing a Subscriber entity. Now, I am in a situation where I have an instance of Mailinglist and need to obtain a list of the first 100 subscribers matching some filter on