我是NHibernate的新手,此查询有一个大问题。 使用NHibernate,查询需要40秒钟才能获得包含12列的8000条记录。 这是我的代码:
实体
Public Class Comuni
Private _ID_Comuni As Integer
Private _Nome_Comune As String
Private _Provincia As String
Private _Nome_Stato As String
Private _Sigla_Stato As String
Private _Europeo As Boolean
Private _Cap As String
Private _Codice_ISTAT As String
Private _Codice_Catastale As String
Private _Tribunale As Boolean
Private _ID_Comuni_Tribunale As Integer?
Private _Popolazione As Integer?
Public Overridable Property IDComuni() As Integer
Get
Return Me._ID_Comuni
End Get
Set
Me._ID_Comuni = Value
End Set
End Property
' All other get and set
End Class
地图代码
Public Class ComuniMap
Inherits ClassMap(Of Comuni)
Public Sub New()
MyBase.New
LazyLoad()
Id(Function(x) x.IDComuni).Column("IDComuni").GeneratedBy().Increment()
Map(Function(x) x.NomeComune).Column("NomeComune")
Map(Function(x) x.Provincia)
Map(Function(x) x.NomeStato).Column("NomeStato")
Map(Function(x) x.SiglaStato).Column("SiglaStato")
Map(Function(x) x.Europeo)
Map(Function(x) x.Cap)
Map(Function(x) x.CodiceISTAT).Column("CodiceISTAT")
Map(Function(x) x.CodiceCatastale).Column("CodiceCatastale")
Map(Function(x) x.Tribunale)
Map(Function(x) x.IDComuniTribunale).Column("IDComuniTribunale")
Map(Function(x) x.Popolazione)
End Sub
End Class
方法
Public Function GetAll() As IList(Of T) Implements IGenericDAO(Of T, S).GetAll
Dim list As IList = New List(Of T)
Dim stateLessSession As IStatelessSession = _sessionFactory.GetCurrentStateLessSession
Try
list = stateLessSession.CreateCriteria(GetType(T)).List(Of T)
Catch ex As Exception
Debug.Print(ex.Message)
logger.Debug(ex.Message)
Throw New Exception()
End Try
Return list
End Function
在调试模式下,以下行:
list = stateLessSession.CreateCriteria(GetType(T)).List(Of T)
始终执行。 使用ADO.NET,相同的查询花费了1.6秒,这是一个可加速的时间,比30秒更现实。 你能帮助我吗?谢谢
我尝试了以下失败的解决方案:
NHibernate query extremely slow compared to hard coded SQL query
在这里: