2012-03-28 2 views
1

Im адресности исключение при е код приходит к этой части:System.OutOfMemoryException жерех чистый MVC

[GridAction] 
     public JsonResult _ForRisk() 
     { 
      var user = current.CurrentUser;    
      var applications = from c in appRepository.GetAll().PendingForRisk(user) 
            let client = c.Clients.FirstOrDefault(t => t.MainOwner == (int)RelationType.Borrower)         
            let timing = c.Timings.Where(t => t.ApplicationID == c.ID && t.Status == (int)AppStatus.Commited).OrderByDescending(t => t.Date).Take(1).FirstOrDefault() 
            select new ApplicationViewModelScreen 
            { 
             ApplicationID = c.ID, 
             Branch = c.Branch.Name, 
             CompanyName = client != null ? client.CompanyName : "", 
             CompanyRegisterNr = client != null ? client.CompanyRegistrationNo : "", 
             DecisionStatus = c.ApplicationStatus, 
             CreateDate = c.RegistrationDate, 
             Submissiondate = timing != null ? timing.Date : new DateTime?(), 
             Inputer = c.User.Name + " " + c.User.Surname, 
            FincAssignedOfficer = c.AssignedOfficerForFinanc != null ? c.AssignedOfficerForFinanc.Name + " " + c.AssignedOfficerForFinanc.Surname : "", 
            CRMAssignedOfficer = c.AssignedOfficerForCRM != null ? c.AssignedOfficerForCRM.Name + " " + c.AssignedOfficerForCRM.Surname : "", 
            CRMIndustry = client.CRMIndustyCode.Description 

            }; 
      var data = applications.ToList(); 

       return Json(new GridModel<ApplicationViewModelScreen> 
       { 
        Data = data, 
        Total = data.Count() 
       }, JsonRequestBehavior.AllowGet); 
     } 

(я использую StructureMap, как DI и я INJEC к контроллеру)

public ApplicationController(
      IApplicationRepository _appRepository, 
      IService<Application> _applicationService, 
      ITargetRepository _targetRepository, 
      IIDGenerator _idGen, 
      ICurrent _current, 
      IProductRepository _productRepository, 
      IUserRepository _userRepository, 
      IDecisionReasonRepository _decisionReason, 
      IInformation _information, 
      IDecisionExceptionRepository _decisionExceptionRepository, 
      ITimingRepository _timingRepository, 
      ITimingDecisionRepository _timingDecisionRepository) 
     { 
      current = _current; 
      idGen = _idGen; 
      appRepository = _appRepository; 
      applicationService = _applicationService; 
      targetRepository = _targetRepository; 
      productRepository = _productRepository; 
      userRepository = _userRepository; 
      decisionReason = _decisionReason; 
      information = _information; 
      decisionExceptionRepository = _decisionExceptionRepository; 
      timingRepository = _timingRepository; 
      timingDecisionRepository = _timingDecisionRepository; 
     } 

Exception

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. 
    at System.Collections.BitArray.set_Length(Int32 value) 
    at System.Data.Query.InternalTrees.VarVec.Align(VarVec other) 
    at System.Data.Query.InternalTrees.NodeInfoVisitor.Visit(FilterOp op, Node n) 
    at System.Data.Query.InternalTrees.FilterOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n) 
    at System.Data.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n) 
    at System.Data.Query.InternalTrees.NodeInfoVisitor.RecomputeNodeInfo(Node n) 
    at System.Data.Query.InternalTrees.Node.InitializeNodeInfo(Command command) 
    at System.Data.Query.InternalTrees.Node.GetExtendedNodeInfo(Command command) 
    at System.Data.Query.InternalTrees.NodeInfoVisitor.Visit(ProjectOp op, Node n) 
    at System.Data.Query.InternalTrees.ProjectOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n) 
    at System.Data.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n) 
    at System.Data.Query.InternalTrees.NodeInfoVisitor.RecomputeNodeInfo(Node n) 
    at System.Data.Query.InternalTrees.Node.InitializeNodeInfo(Command command) 
    at System.Data.Query.PlanCompiler.TransformationRulesContext.PreProcessSubTree(Node subTree) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent) 
    at System.Data.Query.PlanCompiler.TransformationRules.Process(PlanCompiler compilerState, ReadOnlyCollection`1 rulesTable, Boolean& projectionPruningRequired) 
    at System.Data.Query.PlanCompiler.TransformationRules.Process(PlanCompiler compilerState, TransformationRulesGroup rulesGroup) 
    at System.Data.Query.PlanCompiler.PlanCompiler.Compile(List`1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set`1& entitySets) 
    at System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree) 
    at System.Data.EntityClient.EntityProviderServices.CreateCommandDefinition(DbProviderFactory storeProviderFactory, DbCommandTree commandTree) 
    at System.Data.EntityClient.EntityProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree) 
    at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree) 
    at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Span span, ReadOnlyCollection`1 compiledQueryParameters) 
    at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption) 
    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 Corporate.Presentation.MVC.Controllers.ApplicationController._ForRisk() in K:\TempProjects\CorporateAPS\Corporate.Presentation.MVC\Controllers\ApplicationController.cs:line 220 
    at lambda_method(Closure , ControllerBase , Object[]) 
    at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) 
    at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) 
    at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) 
    at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) 
    at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) 
    at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) 
    at System.Web.Mvc.Controller.ExecuteCore() 
    at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) 
    at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) 
    at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5() 
    at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0() 
    at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() 
    at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d() 
    at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) 
    at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) 
    at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) 
    at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) 
    at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 
     Logged on Wednesday, March 28, 2012 at 3:47:20 PM 

ответ

1

Линия:

appRepository.GetAll().PendingForRisk(user) 

Загружает то, что, по-видимому, содержит много строк в памяти. Кроме того, следующие две строки, что делает его хуже:

let client = c.Clients.FirstOrDefault(t => t.MainOwner == (int)RelationType.Borrower)         
let timing = c.Timings.Where(t => t.ApplicationID == c.ID && t.Status == (int)AppStatus.Commited).OrderByDescending(t => t.Date).Take(1).FirstOrDefault() 

Для каждого отдельного appRepository элемента, вы оценки Clients и Timings, для которых может быть много элементов. Вероятно, они были бы ленивы загружены и вносили в память еще много объектов. Проще говоря, исключение понятно - вы одновременно загружаете слишком много объектов в память.

К сожалению, не зная, что такое appRepository (Linq-to-Sql, Entity Framework и т. Д.), Трудно дать какие-либо подсказки о том, как улучшить код. Каков тип возврата appRepository.GetAll().PendingForRisk(user)?

+0

У меня есть аналогичная ошибка - она ​​появляется перед фактическим доступом к базе данных, парсер столкнулся с этим при разборе запроса – Ben

Смежные вопросы