Nhibernate ProjectionList问题

时间:2011-05-23 16:36:15

标签: vb.net nhibernate

我对Nhibernate投影列表有疑问, 它一直说它找不到类'Label6.Domain.Product'中属性'Commname'的setter,或者无法解析属性“pl.commname” 属性“commname”是对象productslangs的一部分。

我的产品对象如下所示:

  Public Overridable Property Latinname() As System.String
            Get
                Return _Latinname
            End Get
            Set(ByVal value As System.String)
                _Latinname = value
            End Set
        End Property
    Public Overridable Property Latinname2() As System.String
        Get
            Return _Latinname2
        End Get
        Set(ByVal value As System.String)
            _Latinname2 = value
        End Set
    End Property

    Public Overridable Property productslangs() As IList(Of Productslang)
        Get
            Return _productslangstrong text
        End Get
        Set(ByVal value As IList(Of Productslang))
            _productslangs = value
        End Set
    End Property

我的标准看起来像这样

Dim crit As ICriteria = session.CreateCriteria(Of Product)()
                crit.Add(Expression.In(Projections.Property("ID"), aryIds))
                crit.CreateAlias("productslangs", "pl")
                crit.Add(Expression.Eq("pl.LangId", systemSettings.setting.langId))
                crit.SetFetchMode("Product.productslangs", FetchMode.Eager)
                crit.SetProjection(Projections.ProjectionList() _
                    .Add(Projections.Property("ID"), "ID") _
                .Add(Projections.Property("this.Latinname"), "Latinname") _
                .Add(Projections.Property("this.Matchcode"), "Matchcode") _
                .Add(Projections.Property("this.Price"), "Price") _
                .Add(Projections.Property("this.Productgroup"), "Productgroup") _
                .Add(Projections.Property("this.colorLookUp"), "colorLookUp") _
                .Add(Projections.Property("this.Productsubgroup"), "Productsubgroup") _
                .Add(Projections.Property("pl.Commname"), "Commname")
                )
                list = crit.SetResultTransformer(Transform.Transformers.AliasToBean(Of Product)).SetCacheable(True).List(Of Product)()

有人可以说出我做错了吗?

1 个答案:

答案 0 :(得分:0)

投影是数据的平面表示。当您指定AliasToBeanTransformer时,它会获取每一行,然后将所有别名映射到您指定的类型的属性。由于Product没有名为Commname的属性,因此会出现抱怨和错误。不确定您要完成的任务,但通常您需要创建一个DTO类,其中包含投影列表中指定的所有属性。然后在AliasToBeanTransformer规范中将它用作bean类。