queryover

NHibernate - filtering out results based on child-property

旧街凉风 提交于 2019-12-06 08:47:43
问题 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

NHibernate child collection Projection to DTO

自古美人都是妖i 提交于 2019-12-06 08:12:02
I have had a good look around for answers on this, and several questions suggest this cannot be done. Nhibernate projection with child collection NHibernate QueryOver projections - projecting collections to DTO NHibernate Projections - how to project collections So I was wondering what would be a good work around to project a child collection to my DTO. Will I need to run two seperate projections and manually add the children to the parent? I am using NH 3.3.1 I have the following DTO data structure public class ProviderDto { public int Id { get; set; } public string Name { get; set; } public

Using current_timestamp in NHibernate QueryOver syntax

两盒软妹~` 提交于 2019-12-06 07:27:57
问题 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(); 回答1: You can use IProjection and SQL functions in the QueryOver API like this: var result =

NHibernate QueryOver association does not contain item

南楼画角 提交于 2019-12-06 06:26:28
问题 could someone help me to translate LINQ expression to Nhibernate QueryOver from m in messages where !m.Recipients.Any(rcpt => rcpt.IsDeleted && rcpt.User = user) I tried this var qry = Session.QueryOver<UserMessage>(); qry.Where(m => m.Recipients.Any(r => !r.IsDeleted && r.User == user)); but got System.Exception : Unrecognised method call: System.Linq.Enumerable:Boolean Any[TSource](System.Collections.Generic.IEnumerable 1[TSource], System.Func 2[TSource,System.Boolean] 回答1: !m.Recipients

How can I select a column within a dictionary value with nhibernate?

江枫思渺然 提交于 2019-12-06 06:01:30
I have structure similar to this: public class Entity { public int Id { get; set; } public IDictionary<string, EntityLocale> Locales { get; set; } } public class EntityLocale { public string Name { get; set; } } public class EntityMap : ClassMap<Entity> { public EntityMap() { HasMany(x => x.Locales) .AsMap<string>("Locale") .Component( c => { c.Map(x => x.Name); } ); } } And I want to recieve all names of product locales with a "en" key. With linq it will be: var names = Session.QueryOver<Product>().List().Select(x => x.Locales["en"].Name).ToList(); How do I achieve this with nhibernate? (I

NHibernate QueryOver CASE WHEN calculate on column value

五迷三道 提交于 2019-12-06 04:24:29
问题 I have been trying to do the following T-SQL in NHibernate QueryOver, but have not succeeded: SELECT Id, SUM(CASE MyValue WHEN 1 THEN Volume ELSE Volume * -1 END) FROM MyTable GROUP BY Id I am trying to sum up all Volume, but for MyValue=1 should be positive values otherwise negative values. So far I got: var result = this.Session.QueryOver<MyTable>() .Select(Projections.Group<MyTable>(x => x.Id), Projections.Conditional(Restrictions.Eq(Projections.Property<MyTable>(x => x.MyValue), '1'),

NHibernate (+ FluentNhibernate) : Join two detached tables

我是研究僧i 提交于 2019-12-05 23:55:12
'tI encounter problems to create a join on two entities with a common property but they are not map together. Say you have an entity Article which contains a property FamilyCode and an entity Family with properties Code and Label. In my mappings, Article doesn't reference Family and i don't want to change that (to keep compatibility with others internal and legacy methods). So, i can't translate the below query in Nhibernate : SELECT f.Code, f.Label FROM Article a INNER JOIN Family f ON a.FamilyCode = f.Code WHERE f.Label LIKE 'p%' I can't use JoinQuery because i can't inject a QueryOver and i

Disjunction on QueryOver<T> always refers to root entity

China☆狼群 提交于 2019-12-05 17:19:25
I'm trying to add a certain numbers of OR conditions using disjunction on X number of entities that implements a certain interface containing date information. My problem is that when the SQL is generated all my disjunction conditions points to the root entity of my QueryOver. I have created a generic method to add my conditions public static QueryOver<T,T2> AddChangedCondition<T,T2>(this QueryOver<T,T2> query, DateTime from, DateTime to, Disjunction disjunction) where T2 : IHaveDate { if(disjunction == null ) disjunction = new Disjunction(); disjunction.Add<T2>(k => (k.DeleteDate > from && k

How to get List of Parent Entities with Child Count In Nhibernate QueryOver

删除回忆录丶 提交于 2019-12-05 14:23:49
I have two classes : public class Parent { public int Id { get; set; } public string Name { get; set; } public ICollection<Child> Childrens { get; set; } } public class Child { public int Id { get; set; } public string Name { get; set; } } Now through Nhibernate QueryOver I want to get list of all Parent with no of Count of children in single query. Expected output is ?: ParentId Name ChildrenCount 1 ABC 10 2 CDE 5 can anyone help me . Using this DTO for projection: public class ParentDto { public int Id { get; set; } public string Name { get; set; } public int ChildrenCount { get; set; } }

NHibernate QueryOver: Get a row count with group by in a subquery

纵饮孤独 提交于 2019-12-05 14:05:14
问题 I'm trying to get a count from a query with a group by and just can't figure out how to translate the SQL I want into NHibernate's QueryOver syntax. This is the SQL: select count(*) from (select Email from Entry where (conditions...) group by Email) as tmp Seems simple right? This is how I'm trying to do it, but the RowCount() call seems to optimize the group by away completely: var query = _unitOfWork.CurrentSession.QueryOver<ContestEntry>() .Select(Projections.Property<ContestEntry>(x => x