queryover

Fluent NHibernate “Could not resolve property”

倖福魔咒の 提交于 2019-11-30 17:43:19
I have read a lot of the questions about that same error but none since to match my exact problem. I'm trying to access the property of an object, itself part of a root object, using Fluent NHibernate. Some answers say I need to use projections, others that I need to use join, and I think it should work through lazy loading. Here are my two classes along with the Fluent mappings: Artist class public class Artist { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual IList<Album> Albums { get; set; } public virtual string MusicBrainzId { get; set; } public

Get children count with restrictions using QueryOver on NHibernate

本小妞迷上赌 提交于 2019-11-30 14:09:19
How can I do the following using QueryOver and no Formula Fields. I have the following parent/child relationship public class Club { public string Name {get; set;} public IList<Membership> Memberships {get; set;} } public class Membership { public boolean Cancelled {get; set;} public Club Club {get; set;} } I have the following query that returns 15 Clubs and transforms the results to a DTO, I need to add to this query a RowCount of Memberships that belong to each club and that are not Cancelled. IEnumerable<ClubIndexViewModelLineSummary> results = _querySession.QueryOver<Club>() .OrderBy(c =>

How to get a distinct result with nHibernate and QueryOver API?

假如想象 提交于 2019-11-30 11:19:53
问题 I have this Repository method public IList<Message> ListMessagesBy(string text, IList<Tag> tags, int pageIndex, out int count, out int pageSize) { pageSize = 10; var likeString = string.Format("%{0}%", text); var query = session.QueryOver<Message>() .Where(Restrictions.On<Message>(m => m.Text).IsLike(likeString) || Restrictions.On<Message>(m => m.Fullname).IsLike(likeString)); if (tags.Count > 0) { var tagIds = tags.Select(t => t.Id).ToList(); query .JoinQueryOver<Tag>(m => m.Tags)

Are there any arithmetic operation projections in NHibernate?

与世无争的帅哥 提交于 2019-11-30 07:30:49
I would like to get this SQL from NHibernate: SELECT SUM(color_pages) * SUM(total_pages) FROM connector_log_entry GROUP BY department_name But I can't find any arithmetic operation (*) projections anywhere. This is the code that I have so far: Session.QueryOver<ConnectorLogEntry>() .SelectList(list => list .SelectGroup(m => m.DepartmentName) .WithAlias(() => dto.Department) .Select(Projections.Sum<ConnectorLogEntry>(m => m.TotalPages)) //.Select(Projections.Sum<ConnectorLogEntry>(m => m.ColorPages)) .WithAlias(() => dto.TotalColorPercentage)) .TransformUsing(Transformers.AliasToBean

QueryOver Or with Subquery

不羁的心 提交于 2019-11-30 06:23:14
问题 IHave the following NHibernate query using a subquery: NHContext.Session.QueryOver<Item>() .WithSubquery.WhereProperty(x => x.ItemId).In(QueryOver.Of<Foo>().Where(x => x.AFlag).Select(x => x.ItemId)) .WithSubquery.WhereProperty(x => x.ItemId).In(QueryOver.Of<Bar>().Where(x => x.AFlag).Select(x => x.Item)) .Future<Item>(); This runs the following SQL: SELECT * FROM item this_ WHERE this_.ItemId in (SELECT this_0_.ItemId as y0_ FROM Foo this_0_ WHERE this_0_.AFlag = 1 /* @p0 */) and this_

NHibernate using QueryOver with WHERE IN

百般思念 提交于 2019-11-29 21:15:50
I would create a QueryOver like this SELECT * FROM Table WHERE Field IN (1,2,3,4,5) I've tried with Contains method but I've encountered the Exception "System.Exception: Unrecognised method call: System.String:Boolean Contains(System.String)" Here my code var qOver = _HibSession.QueryOver<MyModel>(() => baseModel) .JoinAlias(() => baseModel.Submodels, () => subModels) .Where(() => subModels.ID.Contains(IDsSubModels)) .List<MyModel>(); Faber I've found the solution!! :-) var qOver = _HibSession.QueryOver<MyModel>(() => baseModel) .JoinAlias(() => baseModel.Submodels, () => subModels)

Get children count with restrictions using QueryOver on NHibernate

∥☆過路亽.° 提交于 2019-11-29 20:40:19
问题 How can I do the following using QueryOver and no Formula Fields. I have the following parent/child relationship public class Club { public string Name {get; set;} public IList<Membership> Memberships {get; set;} } public class Membership { public boolean Cancelled {get; set;} public Club Club {get; set;} } I have the following query that returns 15 Clubs and transforms the results to a DTO, I need to add to this query a RowCount of Memberships that belong to each club and that are not

Nhibernate subquery with multiple columns join

纵饮孤独 提交于 2019-11-29 17:13:41
I have database structure for Plans and PlanVersions in following relationship: +------+ +-------------+ | Plan | --------------> | PlanVersion | +------+ 1 (1..n) +-------------+ PlanVersion is version table tracking all version changes and it have ActiveFromData and ActiveToData columns show us when was this version active. Plan also can have SubPlans which can change in time so PlanVersion also have ParrentPlanId column which tell us what was current subplan for version. What i want is to get all changes of all SubPlans since some time and for specific Plan. This query is what i came with:

NHibernate QueryOver with WhereRestriction as OR

眉间皱痕 提交于 2019-11-29 15:49:18
I have this query but I can't seem to find how I set my WhereRestrictionOn as an OR. Now they function as AND but I want one OR the other. var privateInfo = Session.QueryOver<ConContact>() .JoinAlias(c => c.PrivateInfos, () => pi) .WhereRestrictionOn(c => c.FirstName).IsLike(_selectedFirstLetter + "%") .WhereRestrictionOn(c => c.LastName).IsLike(_selectedFirstLetter + "%") // todo: change to firstname OR lastname .Where(c => c.Status == ContactStatus.Approved) .Select( Projections.Property("pi.Id").WithAlias(() => sri.Id), Projections.Property("FirstName").WithAlias(() => sri.Name), //todo:

Nhibernate count distinct (based on multiple columns)

久未见 提交于 2019-11-29 14:49:30
Basically, i have been trying to do this (count distinct based on two columns): select count(distinct(checksum(TableA.PropertyA, TableB.PropertyB))) from TableA left outer join TableB on TableA.TableBId = TableB.Id where PropertyA like '%123%' Been googling on how to do this but with no luck. Tried this, but never actually worked. This does not count distinctly based on the two properties from two tables: var queryOver = c.QueryOver<TableA>(); TableB tableBAlias = null; TableA tableAAlias = null; ProjectionList projections = Projections.ProjectionList(); queryOver.AndRestrictionOn(x => x