Une partie de votre instruction SQL est trop profondément nestede. Réécrivez la requête ou divisez-la en requêtes plus petites.

J’ai une action dans mon contrôleur qui appelle la méthode suivante:

public IQueryable getcontactinfo(long[] id) { var organizationsiteids = from accountsitemapping in entities.AccountSiteMappings where id.Any(accountid => accountsitemapping.ACCOUNTID == accountid) select accountsitemapping.SITEID; 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) select userdept; var contactsinfos = from userdept in usersdepts join contactinfo in entities.AaaUserContactInfoes on userdept.USERID equals contactinfo.USER_ID select contactinfo; return contactsinfos; } 

Mais lorsque je lance l’application et que je navigue vers la méthode d’action, l’erreur suivante est générée au niveau de la vue:

 System.Data.EntityCommandExecutionException was unhandled by user code HResult=-2146232004 Message=An error occurred while executing the command definition. See the inner exception for details. Source=System.Data.Entity StackTrace: 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.GetEnumerator() at System.Data.Entity.Internal.Linq.InternalQuery`1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator() at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source) at ASP._Page_Views_Home_CustomersDetails_cshtml.Execute() in c:\Users\Administrator\Desktop\new app DEMO2\MvcApplication4 - LATEST -\MvcApplication4\Views\Home\CustomersDetails.cshtml:line 6 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at System.Web.WebPages.StartPage.RunPage() at System.Web.WebPages.StartPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) at System.Web.Mvc.BuildManagerComstackdView.Render(ViewContext viewContext, TextWriter writer) at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.c__DisplayClass1c.b__19() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) InnerException: System.Data.SqlClient.SqlException HResult=-2146232060 Message=Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries. Source=.Net SqlClient Data Provider ErrorCode=-2146232060 Class=15 LineNumber=105 Number=191 Procedure="" StackTrace: 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.TryConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, Ssortingng resetOptionsSsortingng) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Ssortingng method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Ssortingng method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, Ssortingng method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) InnerException: 

Alors, quelle est la cause de cette erreur?

MIS À JOUR:- entrez la description de l'image ici

LINQ, pour la plupart de ses commandes, utilise une exécution différée. Il attend que vous appeliez les données avant d’envoyer la requête à cette firebase database. Ici, il semble que toutes ces requêtes soient différées à plus tard, lorsque vous essayez de récupérer quelque chose de contactInfos.

J’essaierais de le faire exécuter, par exemple en lançant un fichier .ToList () quelque part, pour essayer de réduire l’imbrication qui se produirait autrement dans le code SQL.

EDIT: Puisque, selon les commentaires, il semble que l’erreur apparaisse lors de la première requête, pourriez-vous essayer de l’ where id.Contains(accountsitemapping.ACCOUNTID) :

Pour référence future, vous pouvez enregistrer le code SQL généré en utilisant:

 var db = new DbContext(); db.Database.Log = Console.Write; 

Cela vous permettra de déterminer quelle partie est profondément nestede. À partir de là, vous devrez peut-être réécrire votre requête pour charger des calculs coûteux dans un deuxième temps. Ou envisagez de l’écrire en tant que procédure stockée.