Sequence不包含匹配元素。 ' /'中的错误应用

时间:2015-08-12 12:29:35

标签: asp.net-mvc

这是我的实体类:

public static Type GetJobItemType(string name)
{
    var result = _JobItemTypes.GetOrAdd(name, x => typeof(JobItemExt).Assembly.GetTypes().Single(y => y.Name == x && typeof(JobItemExt).IsAssignableFrom(y)));
    return result;
}

这就是所谓的

job.Items = multi.Read().Select((p) =>
                {
                    var result = Activator.CreateInstance(JobItemExt.GetJobItemType(p.JobItemTypeName)) as JobItemExt;
                    result.Id = p.Id;
                    result.TenantId = p.TenantId;
                    result.Quantity = p.Quantity;
                    result.ParentId = p.ParentId;
                    result.PaintCost = p.PaintCost;
                    result.ModifiedDate = p.ModifiedDate;
                    result.ModifiedBy = p.ModifiedBy;
                    result.LaborCost = p.LaborCost;
                    result.JobItemTypeName = p.JobItemTypeName;
                    result.JobId = p.JobId;
                    result.DisplayText = p.DisplayText;
                    result.CreatedDate = p.CreatedDate;
                    result.CreatedBy = p.CreatedBy;
                    return result;
                }).ToList();

这是我得到的堆栈跟踪

  

源文件:d:\ saha progs \ CodeProject_New \ dev \ CuttingEdgePainting.Entities \ JobItems \ JobItemExt.cs Line:89   堆栈跟踪:   [InvalidOperationException:Sequence不包含匹配元素]      System.Linq.Enumerable.Single(IEnumerable 1 source, Func 2谓词)+2535897      D:\ saha progs中的CuttingEdgePainting.Entities.JobItems.JobItemExt.b__0(String x)\ CodeProject_New \ dev \ CuttingEdgePainting.Entities \ JobItems \ JobItemExt.cs:89      System.Collections.Concurrent.ConcurrentDictionary 2.GetOrAdd(TKey key, Func 2 valueFactory)+72      D:\ saha progs中的CuttingEdgePainting.Entities.JobItems.JobItemExt.GetJobItemType(String name)\ CodeProject_New \ dev \ CuttingEdgePainting.Entities \ JobItems \ JobItemExt.cs:89      D:\ saha progs中的CuttingEdgePainting.Services.DataServices.JobServiceExt.b__2c(Object p)\ CodeProject_New \ dev \ CuttingEdgePainting.Services \ DataServices \ JobServiceExt.cs:182      System.Linq.WhereSelectEnumerableIterator 2.MoveNext() +145 System.Collections.Generic.List 1..ctor(IEnumerable 1 collection) +381 System.Linq.Enumerable.ToList(IEnumerable 1 source)+58      D:\ saha progs中的CuttingEdgePainting.Services.DataServices.JobServiceExt.GetJob(Int32 id)\ CodeProject_New \ dev \ CuttingEdgePainting.Services \ DataServices \ JobServiceExt.cs:180      D:\ saha progs中的CuttingEdgePainting.ExteriorNew.Controllers.Mobile.JobController.Edit(Int32 id)\ CodeProject_New \ dev \ CuttingEdgePainting.ExteriorNew \ Controllers \ Model \ JobController.cs:91      lambda_method(Closure,ControllerBase,Object [])+ 161      System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller,Object []参数)+59      System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary 2 parameters) +435 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary 2个参数)+60      System.Web.Mvc.Async.ActionInvocation.InvokeSynchronousActionMethod()+76      System.Web.Mvc.Async.AsyncControllerActionInvoker.b__36(IAsyncResult asyncResult,ActionInvocation innerInvokeState)+36      System.Web.Mvc.Async.WrappedAsyncResult 2.CallEndDelegate(IAsyncResult asyncResult) +73 System.Web.Mvc.Async.WrappedAsyncResultBase 1.End()+136      System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+102      System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)+49      System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3c()+ 117      System.Web.Mvc.Async。<> c__DisplayClass45.b__3e()+323      System.Web.Mvc.Async。<> c__DisplayClass30.b__2f(IAsyncResult asyncResult)+44      System.Web.Mvc.Async.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult) +47 System.Web.Mvc.Async.WrappedAsyncResultBase 1.End()+136      System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+102      System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)+50      System.Web.Mvc.Async。<> c__DisplayClass28.b__19()+72      System.Web.Mvc.Async。<> c__DisplayClass1e.b__1b(IAsyncResult asyncResult)+185      System.Web.Mvc.Async.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.WrappedAsyncResultBase 1.End()+133      System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+56      System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+40      System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult,ExecuteCoreState innerState)+34      System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +70 System.Web.Mvc.Async.WrappedAsyncResultBase 1.End()+139      System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+59      System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+40      System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+44      System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult,Controller controller)+39      System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +62 System.Web.Mvc.Async.WrappedAsyncResultBase 1.End()+139      System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+59      System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+40      System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+39      System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)+39      System.Web.Mvc.MvcHandler.b__4(IAsyncResult asyncResult,ProcessRequestState innerState)+39      System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +70 System.Web.Mvc.Async.WrappedAsyncResultBase 1.End()+139      System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+59      System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+40      System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+40      System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)+38      System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+9629708      System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)+155

调试时,我收到字段名c_DisplayClass17的错误(我在字典中也没有)

它在哪里被引用?我正在使用MVC 3 Entity 4.5

1 个答案:

答案 0 :(得分:1)

您得到的错误是因为您使用的Enumerable.Single表达式与枚举中的任何值都不匹配。来自文档:

  

<强>出现InvalidOperationException   没有元素满足谓词中的条件。   -要么-   多个元素满足谓词中的条件。   -要么-   源序列为空。

您可以处理该错误,也可以使用Enumerable.SingleOrDefault,只有在找不到匹配项时才会返回null