이것은 막 시작되었습니다. 이 진술은 몇 달 동안 작동했지만 이제는 아래의 시간 초과 오류가 계속 발생합니다. SSMS에서 똑같은 성명을 직접 실행하면 잠시 후에 다시 돌아옵니다. 테이블은 44k 개의 레코드를 가지며 5 개의 컬럼 상태에 대한 인덱스 중 하나입니다. 내가 계속 시간 초과 오류가 발생하고이 LINQ 문을 실행하고 이전에 제대로 작동 된 이후 아무 생각 y를이없는 경우Linq 문 실행 시간 초과 예외
select distinct(state) from [ZipCodeDatabase]
나는 다음과 같은 LINQ 문
states = ZipCodeRepository.Get(orderBy: z => z.OrderBy(o => o.State)).Select(z => z.State).Distinct().ToList();
을 실행하고 있습니다.
일반적인 repo 기능인 Get()
기능이 포함되어 있지만 지연을 유발하는 내용이 누락되었을 수 있습니다.
가져 오기 기능 :
public virtual IEnumerable<TEntity> Get(
Expression<Func<TEntity, bool>> filter = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
string includeProperties = "") //params Expression<Func<TEntity, object>>[] includes
{
IQueryable<TEntity> query = dbSet;
if (filter != null)
{
query = query.Where(filter);
}
foreach (var includeProperty in includeProperties.Split
(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
query = query.Include(includeProperty);
}
if (orderBy != null)
{
return orderBy(query).ToList();
}
else
{
return query.ToList();
}
}
시간 초과 오류 :
System.Data.SqlClient.SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlDataReader.TryCloseInternal(Boolean closeReader) at System.Data.SqlClient.SqlDataReader.Close() at System.Data.Common.DbDataReader.Dispose(Boolean disposing) at System.Data.Common.DbDataReader.Dispose() at System.Data.Common.Internal.Materialization.Shaper1.Finally() at System.Data.Common.Internal.Materialization.Shaper
1.SimpleEnumerator.Dispose() at System.Collections.Generic.List1..ctor(IEnumerable
1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at ClientsToProfitsKendoUI.DAL.GenericRepository
1.Get(Expression1 filter, Func
2 orderBy, String includeProperties)
이것은 일반적으로 SQL에서 발생하는 유형 변환을 의미합니다. 나는 이것이'datetime'이'nvarchar'로 변환 될 때 일어나는 것을 보았습니다. 쿼리 창에서 1ms 미만의 시간은 코드를 통해 전송할 때 시간 초과됩니다. 확인하는 유일한 방법은 쿼리 프로파일 러를 사용하여 무슨 일이 일어나는지 확인하는 것입니다. –
주를 얻으려고 모든 44K 기록을 구체화하고 있습니까? – McAden