Nhibernate ProjectionList 问题

发布于 2024-11-09 01:27:15 字数 2172 浏览 0 评论 0原文

我对 Nhibernate 投影列表有疑问, 它一直说无法在“Label6.Domain.Product”类中找到属性“Commname”的设置器,或者无法解析属性“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)()

有人能告诉我我做错了什么吗?

I have issue with a Nhibernate projection list,
It keeps saying it Could not find a setter for property 'Commname' in class 'Label6.Domain.Product' or could not resolve property "pl.commname"
the property "commname" is a part of the object productslangs.

My product object looks like this:

  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

My criteria looks like this

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

Can anybody tell what I am doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩世 2024-11-16 01:27:15

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

A projection is a flat representation of your data. When you specify your AliasToBeanTransformer it takes each row and then maps all of the aliases to properties on the type that you specified. Since Product does not have a property called Commname it complains and errors out. Not sure what you're trying to accomplish, but typically you will want to create a DTO class that has all of the properties specified in your projection list. Then use it as your bean class in the AliasToBeanTransformer specification.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文