Hello Markus, thank you, the HQL works in a SimpleQuery. I need the
Criterion for that, cause it's part of a bigger DetachedCriteria
query.
Could you please point me out why this one doesn't work (based on your
HQL):
DetachedCriteria dc = DetachedCriteria.For<Question>("q");
dc.SetResultTransformer(new DistinctRootEntityResultTransformer());
dc.Add(Expression.Sql("q.RelatedQuestions.size > 1"));
IList<Question> res = Question.FindAll(dc);
This would solve my problem, but I get: {"The multi-part identifier
\"q.RelatedQuestions.size\" could not be bound."}.
Regards,
Jakub
On 22 Maj, 17:35, Markus Zywitza <[email protected]> wrote:
> Any reason not to use:
>
> from Question q where q.RelatedQuestions.size > 1
>
> If you are afraid of HQL, try NHibernate
> Workbench:http://nhforge.org/blogs/nhibernate/archive/2010/05/19/nhibernate-wor...
>
> -Markus
>
> 2010/5/22 Cosmo <[email protected]>
>
>
>
> > Hello Guys!
>
> > This SQL works for me:
>
> > select * from Question q where (select COUNT(*) from RelatedQuestion
> > rq where q.Id = rq.ParentId) > 1
>
> > Now I try to convert it to Criteria API:
>
> > DetachedCriteria subCriteria = DetachedCriteria.For<Question>("rq")
>
> > .CreateCriteria("RelatedQuestions").SetProjection(Projections.RowCount())
> > .Add(Restrictions.EqProperty("rq.ParentId", "q.Id"));
>
> > DetachedCriteria criteria =
> > DetachedCriteria.For<Question>("q").Add(Subqueries.Le(1,
> > subCriteria));
> > IList<Question> results = Question.FindAll(criteria);
>
> > As a result I get: "Could not find a matching criteria info provider
> > to: NHibernate.Impl.CriteriaImpl+Subcriteria".
>
> > My mappings are:
>
> > [ActiveRecord("`Question`")]
> > public class Question : ObcykaniDb<Question> {
>
> > private long id;
> > private IList<Question> relatedQuestions;
>
> > [PrimaryKey("`Id`")]
> > private long Id {
> > get { return this.id; }
> > set { this.id = value; }
> > }
>
> > [HasAndBelongsToMany(typeof(Question), ColumnRef = "ChildId",
> > ColumnKey = "ParentId", Table = "RelatedQuestion")]
> > private IList<Question> RelatedQuestions {
> > get { return this.relatedQuestions; }
> > set { this.relatedQuestions = value; }
> > }
> > }
>
> > Any ideas to help me out?
>
> > Regards,
> > Jakub
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Castle Project Users" group.
> > To post to this group, send email to [email protected]
> > .
> > To unsubscribe from this group, send email to
> > [email protected]<castle-project-users%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/castle-project-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" 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
> athttp://groups.google.com/group/castle-project-users?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" 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/castle-project-users?hl=en.