• Linda   2015/8/30 12:45:00
  • 在用Linq查询可为空值的日期时出现:Nullable object must have a value的错误
  • 关键字: Linq 空值 查询
  •  

    Server Error in '/' Application.


    Nullable object must have a value.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.InvalidOperationException: Nullable object must have a value.

    Source Error: 

    Line 171:            if (currentPage == 1)
    Line 172:            {
    Line 173:                return query.Take(pageSize).ToList();
    Line 174:            }
    Line 175:            else

    Source File: E:\Practice\Com.ABC.Mylanqiu\Com.ABC.Mylanqiu\DAL\TeamDAL.cs    Line: 173 

    Stack Trace: 

    [InvalidOperationException: Nullable object must have a value.]
       System.Data.Linq.SqlClient.QueryConverter.VisitInvocation(InvocationExpression invoke) +450
       System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1362
       System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +30
       System.Data.Linq.SqlClient.QueryConverter.VisitBinary(BinaryExpression b) +35
       System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +443
       System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +30
       System.Data.Linq.SqlClient.QueryConverter.VisitConditional(ConditionalExpression cond) +118
       System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +763
       System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +30
       System.Data.Linq.SqlClient.QueryConverter.VisitBinary(BinaryExpression b) +35
       System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +443
       System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +30
       System.Data.Linq.SqlClient.QueryConverter.VisitBinary(BinaryExpression b) +22
       System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +443
       System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +30
       System.Data.Linq.SqlClient.QueryConverter.VisitWhere(Expression sequence, LambdaExpression predicate) +128
       System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) +4102
       System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc) +65
       System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1019
       System.Data.Linq.SqlClient.QueryConverter.VisitOrderBy(Expression sequence, LambdaExpression expression, SqlOrderType orderType) +107
       System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) +9609
       System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc) +65
       System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1019
       System.Data.Linq.SqlClient.QueryConverter.VisitTake(Expression sequence, Expression count) +488
       System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) +10479
       System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc) +65
       System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1019
       System.Data.Linq.SqlClient.QueryConverter.ConvertOuter(Expression node) +101
       System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query, SqlNodeAnnotations annotations) +114
       System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +132
       System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +33
       System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +369
       System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
       Com.ABC.Mylanqiu.DAL.TeamDAL.GetLatestChallengeList(Nullable`1 gameTime, String gameType, String keywords, Int32 currentPage, Int32 pageSize) in E:\Practice\Com.ABC.Mylanqiu\Com.ABC.Mylanqiu\DAL\TeamDAL.cs:173
       Com.ABC.Mylanqiu.BLL.TeamBLL.GetLatestChallengeList(String gameTime, String gameType, String keywords, Int32 currentPage, Int32 pageSize) in E:\Practice\Com.ABC.Mylanqiu\Com.ABC.Mylanqiu\BLL\TeamBLL.cs:250
       Com.ABC.Mylanqiu.Controllers.LeagueController.LatestChallenge() in E:\Practice\Com.ABC.Mylanqiu\Com.ABC.Mylanqiu\Controllers\LeagueController.cs:330
       lambda_method(Closure , ControllerBase , Object[] ) +62
       System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
       System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +214
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
       System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +253
       System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +21
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
       System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324
       System.Web.Mvc.Controller.ExecuteCore() +106
       System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +91
       System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
       System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
       System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
       System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
       System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +48
       System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
       System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9514928
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

大家的回答
  • 还没有人回答这个问题哦,亲,快来帮帮TA吧
  •   我来回答
  • 注册用户登录后才能发表评论,请 登录注册
  • 请您注意

    ·自觉遵守:爱国、守法、自律、真实、文明的原则

    ·尊重网上道德,遵守《全国人大常委会关于维护互联网安全的决定》及中华人民共和国其他各项有关法律法规

    ·严禁发表危害国家安全,破坏民族团结、国家宗教政策和社会稳定,含侮辱、诽谤、教唆、淫秽等内容的作品

    ·承担一切因您的行为而直接或间接导致的民事或刑事法律责任

    ·您在编程中国社区新闻评论发表的作品,本网站有权在网站内保留、转载、引用或者删除

    ·参与本评论即表明您已经阅读并接受上述条款