• 无色无香   2016/2/16 16:08:00
  • Specified cast is not valid
  • 关键字: Linq查询 ExecuteQuery
  •  

    Specified cast is not valid.

    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.InvalidCastException: Specified cast is not valid.

    Source Error: 

    Line 534:    " avg([weight]) as AVGWeight FROM [Com.ABC.MyLanqiu].[dbo].[UserInfo] where UserID in ( SELECT [UserID] " +
    Line 535:" FROM [Com.ABC.MyLanqiu].[dbo].[TeamUserRelation] where TeamID={0})", teamID);
    Line 536:            return dataContext.ExecuteQuery<TeamStatisticsInfo>(sql).FirstOrDefault();
    Line 537:        }
    Line 538:    }

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

    Stack Trace: 

    [InvalidCastException: Specified cast is not valid.]
       System.Data.SqlClient.SqlBuffer.get_Single() +51
       System.Data.SqlClient.SqlDataReader.GetFloat(Int32 i) +62
       Read_TeamStatisticsInfo(ObjectMaterializer`1 ) +1219
       System.Data.Linq.SqlClient.ObjectReader`2.MoveNext() +32
       System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +164
       Com.ABC.Mylanqiu.DAL.TeamDAL.GetTeamStatisticsInfo(Int32 teamID) in E:\Practice\Com.ABC.Mylanqiu\Com.ABC.Mylanqiu\DAL\TeamDAL.cs:536
       Com.ABC.Mylanqiu.BLL.TeamBLL.GetTeamStatisticsInfo(Int32 teamID) in E:\Practice\Com.ABC.Mylanqiu\Com.ABC.Mylanqiu\BLL\TeamBLL.cs:529
       Com.ABC.Mylanqiu.Controllers.LeagueController.Team(String id) in E:\Practice\Com.ABC.Mylanqiu\Com.ABC.Mylanqiu\Controllers\LeagueController.cs:163
       lambda_method(Closure , ControllerBase , Object[] ) +180
       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
    


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18446

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

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

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

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

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

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

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