the example uses Restrictions.Eq or Subquery.PropertyIn but they don't use EqProperty :)
can you try to use the "id" (note the lowercasing) property? i _think_ (but am not sure) that you can always use an implicit "id" property On Tue, Mar 17, 2009 at 10:28 AM, James Crowley <[email protected]>wrote: > Davy, > > Thanks for the response. I had actually come across your blog post, which > was very helpful. However, your examples seem to use > Restrictions.EqProperty... but I don't have a visible "Id" column on > WorkflowTransition - just a direct reference back to it's WorkflowStage > parent? > > Is there a way I can use that property instead? > > Thanks > > James > > 2009/3/15 Davy Brion <[email protected]> > > http://davybrion.com/blog/2008/10/querying-with-nhibernate/ >> >> that has 2 examples of using subqueries >> >> >> On Fri, Mar 13, 2009 at 10:56 AM, James Crowley >> <[email protected]>wrote: >> >>> hey everyone, >>> >>> I've been trying to track down some detailed examples of subqueries using >>> criteria (for either hibernate or nhibernate) but have failed miserably. If >>> there's any good place to look, please do let me know. >>> >>> Failing that... my query looks like this: >>> >>> ICriteria c = _queryService.Session.CreateCriteria(typeof >>> (Content),"content") >>> .CreateAlias("WorkflowStage", "ws") >>> .CreateAlias("Owner", "u") >>> .CreateAlias("ws.TransitionsFromHere", "trn") >>> .Add(Restrictions.Eq("ws.Active", false)) >>> .Add(Restrictions.Eq("u.Id", userContext.Identity.Id)) >>> .Add(Restrictions.In("trn.Role", >>> userContext.Identity.Roles.ToArray())); >>> ... >>> c.SetProjection(p); >>> c.SetResultTransformer(Transformers.AliasToBean(typeof(ContentView))); >>> >>> at the moment. The problem is that really I need an Exists() type query >>> for the last clause, because I only want a each Content element that has at >>> least one "trn.Role" that matches. >>> >>> I've tried doing this: >>> >>> DetachedCriteria rolesCriteria = DetachedCriteria.For(typeof >>> (WorkflowTransition),"trn") >>> .Add(Restrictions.In("Role", userContext.Identity.Roles.ToArray())) >>> .SetProjection(Projections.Property("Id")); >>> >>> ICriteria c = _queryService.Session.CreateCriteria(typeof >>> (Content),"content") >>> .CreateAlias("WorkflowStage", "ws") >>> .CreateAlias("Owner", "u") >>> .Add(Restrictions.Eq("ws.Active", false)) >>> .Add(Restrictions.Eq("u.Id", userContext.Identity.Id)) >>> .Add(Subqueries.Exists(rolesCriteria)); >>> >>> but I'm unsure how to "attach" the detached criteria so it's linked to >>> the content element. I've seen some examples using >>> Restrictions.EqProperty... but I don't have a visible "Id" column on >>> WorkflowTransition - just a direct reference back to it's WorkflowStage >>> parent. >>> >>> Any advice or pointers would be much appreciated! >>> >>> Thanks >>> >>> James >>> >>> >>> >> >> >> > > > -- > James Crowley > Managing Director > Developer Fusion - Connecting developers worldwide > > Developer Fusion Ltd | 58 Sandringham Close | Enfield, EN1 3JH > mob: 07986 624128 web: http://www.developerfusion.com/ > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
