0

C#3.0、Nhibernate 2.1.2、Castle ActiveRecord 2.1、WinXP 32

ActiveRecordとDetachedCriteriaで要素をフィルタリングするのに問題があります。2つのテーブルがあり、1つはフィルタリングされるオブジェクト(PropertyContainer)を含み、もう1つはこのオブジェクトに設定された動的プロパティの値(PropertyValue)を含みます。

PropertyContainer
 Id int

PropertyValue
 Id             int
 ContainerId    int
 Value          real

いくつかの条件に一致するPropertyValueテーブルの値を持つPropertyContainerオブジェクトを選択する必要があります(たとえば、Id =1およびValue>2のプロパティ)。DetachedCriteriaを使用してこれを実行したいのですが、次のようなものを作成しようとしています。

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);

次に、この呼び出しが実行されます。次のエラーが発生します:「プロパティを解決できませんでした:ExternalProperty of:PropertyContainer」

質問は:

  1. このアプローチの何が問題になっていますか?
  2. ActiveRecord / NHibernateとDetachedCriteriaを使用して動的プロパティセットでフィルタリングを行う正しい方法は何ですか?
4

1 に答える 1

1

PropertyValueが次のようになっている場合:

class PropertyValue
{
    public virtual int Id { get; set; }
    public virtual double Value { get; set; }
}

できるよ:

DetachedCriteria.For<PropertyContainer>()
    .CreateAlias("PropertyValues", "prop")
    .Add(Restrictions.Ge("prop.Value", 2))
    .Add(Restrictions.Eq("prop.Id", 1));
于 2011-06-15T12:56:24.257 に答える