asp.net mvc Webアプリケーション内にfolloiwngメソッドがあり、データアクセスレイヤーとしてEntity Frameworkを使用しています:-
public IEnumerable<AaaUserContactInfo> getcontactinfo(long[] id)
{
var organizationsiteids = (from accountsitemapping in entities.AccountSiteMappings
where id.Any(accountid => accountsitemapping.ACCOUNTID == accountid)
select accountsitemapping.SITEID).ToList();
var usersdepts = from userdept in entities.UserDepartments
join deptdefinition in entities.DepartmentDefinitions on userdept.DEPTID equals deptdefinition.DEPTID
where organizationsiteids.Any(accountid => deptdefinition.SITEID == accountid)
var contactsinfos = from contactinfo in entities.AaaUserContactInfoes
join userdept in usersdepts on contactinfo.USER_ID equals userdept.USERID
select contactinfo;
return contactsinfos;
しかし、レコードの数が膨大な場合は、次のエラーが発生します:-
SQLステートメントの一部がネストされすぎています。クエリを書き直すか、より小さなクエリに分割します。説明:現在のWebリクエストの実行中に未処理の例外が発生しました。エラーとエラーがコードのどこで発生したかについての詳細は、スタックトレースを確認してください。
例外の詳細:System.Data.SqlClient.SqlException:SQLステートメントの一部がネストされすぎています。クエリを書き直すか、より小さなクエリに分割します。
ソースエラー:
現在のWebリクエストの実行中に、未処理の例外が生成されました。例外の発生源と場所に関する情報は、以下の例外スタックトレースを使用して識別できます。
スタックトレース:
[SqlException(0x80131904):SQLステートメントの一部がネストされすぎています。クエリを書き直すか、より小さなクエリに分割します。]
System.Data.SqlClient.SqlConnection.OnError(SqlException例外、ブール値breakConnection、アクション1完了、Int32タイムアウト、タスクとタスク、ブール値asyncWrite)+577 System.Data.SqlClient.SqlCommand .RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior runBehavior、Boolean returnStream、String method)+107 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior Behavior、String method)+288 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior Behavior)+1801 wrapCloseInAction) +388
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +688
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4403
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +82
System.Data.SqlClient.SqlDataReader.get_MetaData() +135
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6665229
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) +6667096
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource
System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand、CommandBehavior Behavior)+689
返されるレコードの数が少ない場合、コードは正常に機能しますが、何が問題になる可能性がありますか?