NHibernate JoinQueryOver和转换-NHibernate.Exceptions.GenericADOException无法执行查询

时间:2019-03-09 16:41:09

标签: vb.net nhibernate inner-join queryover

我正在Vb.Net和NHibernate中开发一个Web应用程序。 我想通过两个对象之间的NHibernate(NO CreateSQLQuery)执行一个示例内部联接。尽管出现错误,我正在尝试以下代码块。

Dim list As IList = New List(Of AttiByEnteDTO)

Dim attiByEnteDTO As AttiByEnteDTO = Nothing
Dim attiAlias As Atti = Nothing
Dim schedaEnteAlias As SchedaEnte = Nothing
ist = session.QueryOver(Of Atti)(Function() attiAlias) _
                    .JoinQueryOver(Of SchedaEnte)(Function(p) p.Scheda_Ente, Function() schedaEnteAlias) _
                    .SelectList(Function(l) l _
                        .Select(Function(a) attiAlias.Descrizione).WithAlias(Function() attiByEnteDTO.Descrizione) _
                        .Select(Function(a) attiAlias.Scadenza).WithAlias(Function() attiByEnteDTO.Scadenza) _
                        .Select(Function(a) schedaEnteAlias.Ragione_Sociale).WithAlias(Function() attiByEnteDTO.Ragione_Sociale)) _
                .TransformUsing(Transformers.AliasToBean(Of AttiByEnteDTO)).List(Of AttiByEnteDTO)()

这是错误消息(来自try-catch块):

could not execute query
[ SELECT this_.Descrizione as y0_, this_.Scadenza as y1_, alias_$vb$local_1_.RagioneSociale as y2_ from  `Atti` this_ inner join `SchedaEnte` alias_$vb$local_1_ on this_.IDEnte=alias_$vb$local_1_.IDEnte ]
[SQL: SELECT this_.Descrizione as y0_, this_.Scadenza as y1_, alias_$vb$local_1_.RagioneSociale as y2_ from  `Atti` this_ inner join `SchedaEnte` alias_$vb$local_1_ on this_.IDEnte=alias_$vb$local_1_.IDEnte]

和内部异常消息

{"Syntax error in FROM clause."}

映射类Atti和SchedaEnte

Public Class AttiMap
        Inherits ClassMap(Of Atti)

        Public Sub New()
            MyBase.New
            LazyLoad()
            Id(Function(x) x.IDAtto).Column("IDAtto").GeneratedBy().Increment()
            Map(Function(x) x.Descrizione)
            Map(Function(x) x.Scadenza)
            References(Function(x) x.Scheda_Ente, "IDEnte")
        End Sub
    End Class

 Public Class SchedaEnteMap
        Inherits ClassMap(Of SchedaEnte)

        Public Sub New()
            MyBase.New
            LazyLoad()
            Id(Function(x) x.ID_Ente).Column("IDEnte").GeneratedBy().Increment()
            Map(Function(x) x.Ragione_Sociale).Column("RagioneSociale")
            HasMany(Function(x) x.ListAtti).KeyColumn("IDEnte")
        End Sub
    End Class

域类Atti和SchedaEnte

Public Class Atti

        Private _ID_Atto As Integer?
        Private _Descrizione As String
        Private _Scadenza As Integer?
        Private _Scheda_Ente As SchedaEnte

        Public Overridable Property IDAtto() As Integer?
            Get
                Return Me._ID_Atto
            End Get
            Set(value As Integer?)
                Me._ID_Atto = Value
            End Set
        End Property

        Public Overridable Property Descrizione() As String
            Get
                Return Me._Descrizione
            End Get
            Set
                Me._Descrizione = Value
            End Set
        End Property

        Public Overridable Property Scadenza() As Integer?
            Get
                Return Me._Scadenza
            End Get
            Set
                Me._Scadenza = Value
            End Set
        End Property
        Public Overridable Property Scheda_Ente As SchedaEnte
            Get
                Return _Scheda_Ente
            End Get
            Set(value As SchedaEnte)
                _Scheda_Ente = value
            End Set
        End Property
End Class

Public Class SchedaEnte

        Private _ID_Ente As Integer?
        Private _Ragione_Sociale As String
        Private _ListAtti As IList(Of Atti)

        Public Overridable Property ID_Ente() As Integer?
            Get
                Return Me._ID_Ente
            End Get
            Set
                Me._ID_Ente = Value
            End Set
        End Property

        Public Overridable Property Ragione_Sociale() As String
            Get
                Return Me._Ragione_Sociale
            End Get
            Set
                Me._Ragione_Sociale = Value
            End Set
        End Property

        Public Overridable Property ListAtti As IList(Of Atti)
            Get
                Return _ListAtti
            End Get
            Set(value As IList(Of Atti))
                _ListAtti = value
            End Set
        End Property
End Class

DTO类

Public Class AttiByEnteDTO

        Private _Descrizione As String
        Private _Scadenza As Integer?
        Private _Ragione_Sociale As String

        Public Property Descrizione() As String
            Get
                Return Me._Descrizione
            End Get
            Set(value As String)
                Me._Descrizione = value
            End Set
        End Property

        Public Property Scadenza() As Integer?
            Get
                Return Me._Scadenza
            End Get
            Set(value As Integer?)
                Me._Scadenza = value
            End Set
        End Property

        Public Property Ragione_Sociale() As String
            Get
                Return Me._Ragione_Sociale
            End Get
            Set(value As String)
                Me._Ragione_Sociale = value
            End Set
        End Property
End Class

有人可以举例说明我为什么吗?
预先谢谢你。

0 个答案:

没有答案