2

I Compose NHibernate Query using Criterion

Junction criterion = Restrictions.Conjunction();
criterion.Add(something1);
criterion.Add(something2);
....
criterion.Add(somethingN);

and how can I get count of criteries in criterion like criterion.GetCountOfCriteries()

In Source code of Junction I see list of criteries

private readonly IList<ICriterion> criteria = new List<ICriterion>();

but it has modifier as private.

Some ideas?

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
Dr_klo
  • 469
  • 6
  • 19

1 Answers1

2

It is not possible. And it is not intended. Why? Because we work with ICriteria API and not with its implementation (what we can see in code or debugger).

So, if there will be different implementation of ICriteria... none can grant there will be some readonly ILIst<ICriterion> at all...

As a solution I would suggest - do that outside of the ICriteria API (if really needed). And, maybe try to re-check if such information is needed.

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • Temporary, I Implemented my custom Junction that has property Count `public int Count { get { return criteria.Count; }}` And then implement custom Conjunction and Disjunction class that inherited from MyJunction. Is it good practice? – Dr_klo Nov 10 '15 at 05:00
  • 1
    That is brilliant solution. Why? Because that 1) firstly not only proves the concept of extensiblity of the NHibernate 2) it really gives you the power to manage your stuff. Because, you are adding expected objects (interfaces) to NHibernate *(implementing the publisehd API, e.g. `ICriterion`)* while keeping private features independent on the NHibernate API. GREAT solution. That is called OOP ;) ;) ;) – Radim Köhler Nov 10 '15 at 05:32