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

C# 实体框架错误,一个表总是超时,c#,mysql,asp.net-mvc,linq,entity-framework,C#,Mysql,Asp.net Mvc,Linq,Entity Framework,我有以下代码从5个不同的表中从DB获取特定的用户详细信息 var userValues = usrRepository.AsQueryable() .Where(user => user.UserType == (int)GlobalEnumeration.UserType.MDappUser && user.IsActive == true) .Include(f => f.appusraddrs) .Include(c => c.us

我有以下代码从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();
但是,当我尝试使用最后一个include
include.include(“usrAttributes.usrAttributeValues.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)
在System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext上下文,ObjectParameterCollection parameterValues)
位于System.Data.Objects.ObjectQuery`1.GetResults(可为null`1 forMergeOption)
位于System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()
位于System.Collections.Generic.List`1..ctor(IEnumerable`1集合)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
在MyBusiness.Business.SearchIndexing.SearchIndexBC.GetMyBusinessDetails()中
在MyBusiness.Framework.Indexing.Services.IndexingTaskExecutor.BatchIndex(字符串indexName、字符串设置文件名、IndexSettings IndexSettings)
在MyBusiness.Framework.Indexing.Services.IndexingTaskExecutor.UpdateIndexBatch(字符串indexName)
在MyBusiness.Business.ProfileManagement.ProfileManagementBC.UpdateOtherDetails(appuser)

通过添加
((IObjectContextAdapter)this.context)来延长
ObjectContext的超时时间,从而解决了问题。ObjectContext.CommandTimeout=180

什么是
usrRepository
?它是什么类型的?如果你需要AsQueryable,那会让我很紧张。。。您看过生成的SQL吗?您有多少数据?亲爱的Jon,这是一个存储库,appuserRepository userRepository=新的appuserRepository(unitOfWork);其中appuserRepository是appuser Entity类型的存储库,那么它是否已经实现了
IQueryable
?那么为什么要调用
AsQueryable
?我建议您删除它,除非您真的需要它…很抱歉,我在没有AsQueryable()的情况下很难形成查询,因为我在Linq方面不是很好。我认为它应该从var userValues=usrRepository.GetAll()开始?不确定。问题不是超时长度,问题是它为什么会超时?
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)