2011-02-08 49 views
0

我有一个设置,我有一个表,有两个字段,FirstName和LastName。为了在名称中进行搜索,我制定了一个包含FirstName + " " + Lastname的公式。NHibernate标准和公式

但是,如果我尝试做如下声明:

Restrictions.InsensitiveLike("empl.FullNameFormula", "% " + restriction.PersonName + " %") 

我收到的错误:

“过期超时操作或服务器完成前经过的超时时间没有响应。 “。

但是,如果我尝试做的,而不是像它的工作原理相同:

Restrictions.Eq("empl.FullNameFormula", "% " + restriction.PersonName + " %") 

是否有与式,并试图做这样一个敏感的错误?

我使用的是NHibernate版本2.1.2.4000。

更新: 我的堆栈跟踪看起来是这样的:

[SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.] 
    System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1951450 
    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4849003 
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194 
    System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2394 
    System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33 
    System.Data.SqlClient.SqlDataReader.get_MetaData() +83 
    System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297 
    System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954 
    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162 
    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32 
    System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141 
    System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12 
    System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() +12 
    NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) +216 
    NHibernate.Impl.MultiCriteriaImpl.GetResultsFromDatabase(IList results) +310 
    NHibernate.Impl.MultiCriteriaImpl.List() +348 
    NHibernate.Impl.FutureCriteriaBatch.GetResultsFrom(IMultiCriteria multiApproach) +10 
    NHibernate.Impl.FutureBatch`2.GetResults() +88 
    NHibernate.Impl.FutureBatch`2.get_Results() +16 
    NHibernate.Impl.FutureBatch`2.GetCurrentResult(Int32 currentIndex) +52 
    NHibernate.Impl.<>c__DisplayClass4`1.<GetEnumerator>b__3() +53 
    NHibernate.Impl.<get_Enumerable>d__0.MoveNext() +73 
    System.Linq.Buffer`1..ctor(IEnumerable`1 source) +259 
    System.Linq.Enumerable.ToArray(IEnumerable`1 source) +81 
    xxx.DataAccess.PublicationRepository.Search(PublicationQuery restriction) in xxxx :197 
    layouts_www_xxx.RunSearch() in xxx:100 
    layouts_www_xxx.OnInit(EventArgs e) in xxxx :39 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +333 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +378 
+0

什么是生成的第一条语句的SQL,我会发现这一点,然后对数据库运行它来追踪您的问题。我怀疑这里有一个数据库问题。 – Rippo 2011-02-08 11:18:13

+0

也说明了这个片段在这个片段上执行的总数rownum – Jaguar 2011-02-08 11:20:39

+0

@Jaguar:它将在成千上万的行上执行,所以没有什么大的。 – Dofs 2011-02-08 13:08:38

回答

1

I would see what the actual SQL is being generated, you mention that this is part of a much larger search...

因此,基于这一点,我要么: -

一)火了SQL事件探查器,并看到正在生成的SQL和SQL管理运行这个工作室

B)下载NHProf和抢SQL和SQL Management Studio中

C)使用log4net的运行输出生成的SQL和SQL管理运行工作室

我假设这是一个MsSQL服务器,如果不使用MySql Workbench。

这真的是SQL数据库问题的气味,而不是NHibernate的问题。如果没有首先检查SQL,你可能会吼出错误的树。

HTH

1

你可能会对姓是帮助第一查询的索引,而第二个是做昂贵的表扫描。