CollectionType是必需的。参数名称:collectionType

时间:2015-01-28 09:02:02

标签: c# asp.net-mvc linq entity-framework

我在我的应用程序中使用ASP.NET MVC和Entity Framework。我明白了 发布项目并放入生产服务器时出现A CollectionType is required. Parameter name: collectionType错误。但我不会在自己的电脑上得到它。这是我的代码

var model = DB.RFH_ComplexRequest.Where(
            d => (d.FKRequestPeriodID == requestPeriodID || requestPeriodID == null)
                 && (d.RFH_Personel.PersonelCode == personelCode || personelCode == "")
                 && (String.Compare(d.StartDate, fromDate) >= 0 || fromDate == "")
                 && (String.Compare(d.EndDate, toDate) <= 0 || toDate == "")
                 && (d.RequestCode == requestCode || requestCode == null)
                 && (d.FKComplexRequestStatusID == requestStatus || requestStatus == null)
                 && (d.FKComplexID == complex || complex == null)
                 && (d.FKComplexRequestRegistrationTypeID == registrationType || registrationType == null)
                 && (d.FKComplexRequestTypeID == requestType || requestType == null))                     
                .Select(d => new AllRequestsViewModel
                    {
                        PKComplexRequestID = d.PKComplexRequestID,                            
                        RequestCode = d.RequestCode,
                        UsageHistory = 0,
                        EmploymentHistory = 0,                            
                        StatusName = d.RFH_ComplexRequestStatus.ComplexRequestStatusName,                                                                                   
                        FKPersonelID = d.FKPersonelID,
                        Status = d.FKComplexRequestStatusID,
                        PersonelCode = d.RFH_Personel.PersonelCode,
                        PersonelName = d.RFH_Personel.PersonelName,
                        PersonelFamily = d.RFH_Personel.PersonelFamily,                            
                        RequestDayCount = d.RequestDayCount,
                        ComplexName = d.RFH_Complex != null ? d.RFH_Complex.ComplexName : "",
                        DepartmentName = d.RFH_Personel.RFH_Department.DepartmentName,
                        RegisterDate = d.RegisterDate,
                        StartDate = d.StartDate,
                        EndDate = d.EndDate,
                        ComplexRequestTypeName = d.RFH_ComplexRequestType.ComplexRequestTypeName,
                        RequestPeriodName = d.RFH_RequestPeriod != null ? d.RFH_RequestPeriod.RequestPeriodName : ""
                    }).
            ToList();
        foreach (var complexRequest in model)
        {
            // Get last use and calculate usage history
            var requestTypeList =
                DB.RFH_ComplexRequestType.Where(d => d.AffectsUsagePriority)
                    .Select(d => d.PKComplexRequestTypeID)
                    .ToList();
            var statusList = new List<byte>
            {
                //Convert.ToByte(ComplexRequestStatus.UserConfirmed),
                //Convert.ToByte(ComplexRequestStatus.RoomAllocated),
                //Convert.ToByte(ComplexRequestStatus.SecondSignatureConfirmed),
                //Convert.ToByte(ComplexRequestStatus.Confirmed),
                Convert.ToByte(ComplexRequestStatus.Used)
            };
            var lastUsage = DB.RFH_ComplexRequest.Where(
                      r => r.PKComplexRequestID != complexRequest.PKComplexRequestID &&
                        r.FKPersonelID == complexRequest.FKPersonelID &&
                        r.FKRequestPeriodID != requestPeriodID &&
                        statusList.Contains(r.FKComplexRequestStatusID) &&
                        (requestTypeList.Any() && requestTypeList.Contains(r.FKComplexRequestTypeID)) &&
                        (r.RFH_Complex != null && r.RFH_Complex.AffectsUsagePriority &&
                        r.RFH_Complex.UsagePriorityAffectDays != null &&
                        r.RequestDayCount >= r.RFH_Complex.UsagePriorityAffectDays))
                .OrderByDescending(r => r.StartDate).FirstOrDefault();
            if (lastUsage != null)
            {
                complexRequest.UsageHistory = CGeneralDef.ShamsiYearDiff(lastUsage.StartDate,
                    CGeneralDef.GetCurrentShamsiDate());
                complexRequest.LastUsageDate = lastUsage.StartDate;
            }
            else
            {
                complexRequest.UsageHistory = 100;                    
                complexRequest.LastUsageDate = "0000/00/00";
            }
            var personel = DB.RFH_Personel.Single(r => r.PKPersonelID == complexRequest.FKPersonelID);
            if (personel != null && !String.IsNullOrEmpty(personel.EmploymentDate))
                complexRequest.EmploymentHistory = CGeneralDef.ShamsiYearDiff(personel.EmploymentDate, CGeneralDef.GetCurrentShamsiDate());
            else
                complexRequest.EmploymentHistory = 0;                

        }

这是我的堆栈跟踪:

[ArgumentException: A CollectionType is required. Parameter name: collectionType] System.Data.Common.CommandTrees.ExpressionBuilder.Internal.ArgumentValidation.ValidateNewEmptyCollection(TypeUsage collectionType, DbExpressionList& validElements) +11017011 System.Data.Objects.ELinq.NewArrayInitTranslator.TypedTranslate(ExpressionConverter parent, NewArrayExpression linq) +285 System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +369 System.Data.Objects.ELinq.ConstantTranslator.TypedTranslate(ExpressionConverter parent, ConstantExpression linq) +603 System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +369 System.Data.Objects.ELinq.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call) +83 System.Data.Objects.ELinq.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq) +222 System.Data.Objects.ELinq.BinaryTranslator.TypedTranslate(ExpressionConverter parent, BinaryExpression linq) +180 System.Data.Objects.ELinq.BinaryTranslator.TypedTranslate(ExpressionConverter parent, BinaryExpression linq) +327 System.Data.Objects.ELinq.BinaryTranslator.TypedTranslate(ExpressionConverter parent, BinaryExpression linq) +180 System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input) +244 System.Data.Objects.ELinq.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda) +322 System.Data.Objects.ELinq.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call) +61 System.Data.Objects.ELinq.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq) +222 System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +369 System.Data.Objects.ELinq.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda) +79 System.Data.Objects.ELinq.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call) +61 System.Data.Objects.ELinq.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq) +222 System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +369 System.Data.Objects.ELinq.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call) +83 System.Data.Objects.ELinq.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq) +222 System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +369 System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable 1 forMergeOption)+296    System.Data.Objects.ObjectQuery 1.GetResults(Nullable 1 forMergeOption)+10985849    System.Data.Objects.ObjectQuery 1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +47 System.Linq.Enumerable.FirstOrDefault(IEnumerable 1 source)+220    System.Linq.Queryable.FirstOrDefault(IQueryable 1 source) +383 RefahiWeb.Controllers.ComplexRequestController.AllRequests(Nullable 1 requestPeriodID,String personelCode,String fromDate,String toDate,Nullable 1 requestStatus, Nullable 1 complex,Nullable 1 registrationType, Nullable 1 requestCode,Nullable 1 requestType, Boolean firstReference) +12644 lambda_method(Closure , ControllerBase , Object[] ) +655 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary 2参数)+261    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext,ActionDescriptor actionDescriptor,IDictionary 2 parameters) +39 System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +34 System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +129 System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +920775 System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +15 System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +33 System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +921580 System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +20 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +67 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +20 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +53 System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +20 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +53 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371

提前感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

找到它。 requestTypeList为null。