2014-01-07 45 views
0

我有以下代碼從DB獲取來自5個不同表的特定用戶詳細信息。實體框架錯誤,一個表總是超時

var userValues = usrRepository.AsQueryable() 
.Where(user => user.UserType == (int)GlobalEnumeration.UserType.MDappUser && user.IsActive == true) 
.Include(f => f.appusraddrs) 
.Include(c => c.usrcalendar) 
.Include(f => f.usrattributes) 
.Include("usrAttributes.usrAttributeValues") 
.Include("usrAttributes.usrAttributeValues.ApplicationAttributeValue") 
.ToList(); 

不過,我總是得到超時錯誤當過我嘗試包括使用最後一個包含(.Include("usrAttributes.usrAttributeValues.ApplicationAttributeValue"))表「ApplicationAttributeValue」。

如果我沒有包含該表,我不會收到任何錯誤。

錯誤堆棧

MySql.Data.MySqlClient.MySqlException (0x80004005): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.TimeoutException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond ---> System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) 
--- End of inner exception stack trace --- 
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) 
at MySql.Data.Common.MyNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count) 
--- End of inner exception stack trace --- 
at MySql.Data.Common.MyNetworkStream.HandleOrRethrowException(Exception e) 
at MySql.Data.Common.MyNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count) 
at MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count) 
at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count) 
at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count) 
at MySql.Data.MySqlClient.MySqlStream.LoadPacket() 
at MySql.Data.MySqlClient.MySqlStream.ReadPacket() 
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) 
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) 
at MySql.Data.MySqlClient.MySqlDataReader.NextResult() 
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) 
at MySql.Data.MySqlClient.ExceptionInterceptor.Throw(Exception exception) 
at MySql.Data.MySqlClient.MySqlConnection.HandleTimeoutOrThreadAbort(Exception ex) 
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) 
at MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) 
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) 

而且

at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) 
at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues) 
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) 
at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() 
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) 
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) 
at MyBusiness.Business.SearchIndexing.SearchIndexBC.GetMyBusinessDetails() 
at MyBusiness.Framework.Indexing.Services.IndexingTaskExecutor.BatchIndex(String indexName, String settingsFilename, IndexSettings indexSettings) 
at MyBusiness.Framework.Indexing.Services.IndexingTaskExecutor.UpdateIndexBatch(String indexName) 
at MyBusiness.Business.ProfileManagement.ProfileManagementBC.UpdateOtherDetails(appuser user) 
+0

什麼* *究竟是'usrRepository'解決了嗎?它的類型是什麼?如果你需要* AsQueryable,那讓我感到緊張......你看過生成的SQL嗎?你有多少數據? –

+0

親愛的Jon它是一個倉庫,appuserRepository userRepository =新的appuserRepository(unitOfWork); appuserRepository在哪裏是appuser實體類型的倉庫 – TBA

+0

那麼它是不是已經實現了'IQueryable '? –

回答

0

得到通過延長ObjectContext超時加入((IObjectContextAdapter)this.context).ObjectContext.CommandTimeout = 180;

+0

問題不在於超時長度,問題是爲什麼它會超時? – AnovaConsultancy