C# 3.0, Nhibernate 2.1.2 , Castle ActiveRecord 2.1, WinXP 32
I have a problem filtering elements with ActiveRecord and DetachedCriteria.
There are 2 tables one contains the objects to be filtered (PropertyContainer) and the other contains the values of dymamic property set for this object (PropertyValue).
PropertyContainer
Id int
PropertyValue
Id int
ContainerId int
Value real
I need to select PropertyContainer object with the values from PropertyValue table matching some condition (e.g. property with Id = 1 and Value > 2). I would like to do this using DetachedCriteria, I am trying to write something like this:
var detachedCriteria = DetachedCriteria.For(typeof(PropertyContainer));
detachedCriteria.SetProjection(
Projections.SqlProjection(@"select Value from PropertyValue where Id=1"),
new[] { "ExternalProperty" },
new[] { NHibernateUtil.Double }));
detachedCriteria.Add(Expression.Ge("ExternalProperty",2));
var filteredItems = PropertyContainer.SlicedFindAll(0,100,detachedCriteria);
Then this call is executed I get the following error:
“could not resolve property: ExternalProperty of: PropertyContainer”
The question is:
- What is wrong with this approach ?
- What is the right way to do filtration by dynamic property set using ActiveRecord/NHibernate and DetachedCriteria ?
if PropertyValue looks like:
you can do: