实体框架错误,一个表总是超时

时间:2022-10-10 10:01:12

I have following code to get a particular user details from DB, from 5 different tables.

我有以下代码从5个不同的表中获取DB的特定用户详细信息。

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

However I always get the Timeout error when ever I try to include the table "ApplicationAttributeValue" using the last include (.Include("usrAttributes.usrAttributeValues.ApplicationAttributeValue")).

但是,当我尝试使用最后一个include(.Include(“usrAttributes.usrAttributeValues.ApplicationAttributeValue”))包含表“ApplicationAttributeValue”时,我总是得到Timeout错误。

If I did not include that table I will not get any error.

如果我没有包含该表,我将不会收到任何错误。

Error Stack

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)

And

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)

1 个解决方案

#1


0  

Got solved by extending timeout for ObjectContextby adding ((IObjectContextAdapter)this.context).ObjectContext.CommandTimeout = 180;

通过扩展ObjectContextby的超时来解决((IObjectContextAdapter)this.context).ObjectContext.CommandTimeout = 180;

#1


0  

Got solved by extending timeout for ObjectContextby adding ((IObjectContextAdapter)this.context).ObjectContext.CommandTimeout = 180;

通过扩展ObjectContextby的超时来解决((IObjectContextAdapter)this.context).ObjectContext.CommandTimeout = 180;