1

我收到一般错误消息 System.Linq.Dynamic.ParseException: Identifier expected。

我应该检查什么才能解决它?错误不是很详细。

我确实检查了 ParseLambda 方法中的源和选择器参数,它们携带的 T-SQL 似乎有效并且在 SQL Management Studio 中执行得很好。

 Server Error in '/' Application.
________________________________________
Identifier expected 
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.Linq.Dynamic.ParseException: Identifier expected

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 

[ParseException: Identifier expected]
   System.Linq.Dynamic.ExpressionParser.ValidateToken(TokenId t, String errorMessage) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:1952
   System.Linq.Dynamic.ExpressionParser.GetIdentifier() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:1941
   System.Linq.Dynamic.ExpressionParser.ParseNew() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:1038
   System.Linq.Dynamic.ExpressionParser.ParseIdentifier() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:966
   System.Linq.Dynamic.ExpressionParser.ParsePrimaryStart() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:867
   System.Linq.Dynamic.ExpressionParser.ParsePrimary() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:848
   System.Linq.Dynamic.ExpressionParser.ParseUnary() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:844
   System.Linq.Dynamic.ExpressionParser.ParseMultiplicative() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:798
   System.Linq.Dynamic.ExpressionParser.ParseAdditive() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:771
   System.Linq.Dynamic.ExpressionParser.ParseComparison() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:702
   System.Linq.Dynamic.ExpressionParser.ParseLogicalAnd() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:689
   System.Linq.Dynamic.ExpressionParser.ParseLogicalOr() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:676
   System.Linq.Dynamic.ExpressionParser.ParseExpression() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:662
   System.Linq.Dynamic.ExpressionParser.Parse(Type resultType) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:629
   System.Linq.Dynamic.DynamicExpression.ParseLambda(ParameterExpression[] parameters, Type resultType, String expression, Object[] values) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:166
   System.Linq.Dynamic.DynamicExpression.ParseLambda(Type itType, Type resultType, String expression, Object[] values) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:161
   System.Linq.Dynamic.DynamicQueryable.Select(IQueryable source, String selector, Object[] values) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:34
   WebUI.Controllers.VoterController.ExportToExcel() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\Controllers\VoterController.cs:2288
   lambda_method(Closure , ControllerBase , Object[] ) +62
   System.Web.Mvc.<>c__DisplayClass1.<WrapVoidAction>b__0(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   Castle.Proxies.ControllerActionInvokerProxy.InvokeActionMethod_callback(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +42
   Castle.Proxies.Invocations.ControllerActionInvoker_InvokeActionMethod.InvokeMethodOnTarget() +208
   Castle.DynamicProxy.AbstractInvocation.Proceed() +56
   Glimpse.Mvc3.Interceptor.InvokeActionMethodInterceptor.Intercept(IInvocation invocation) +408
   Castle.DynamicProxy.AbstractInvocation.Proceed() +94
   Castle.Proxies.ControllerActionInvokerProxy.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +222
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
   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) +343
   System.Web.Mvc.Controller.ExecuteCore() +116
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
   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() +8970141
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

________________________________________
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

第 1952 行的 ParseException:

第 1952 行的 ParseException

调用堆栈异常源:

在此处输入图像描述

4

1 回答 1

3

好的,我不知道这是否是 System.Linq.Dynamic 库中的 Microsoft 错误或 SQL 列别名的滥用,但在这种特殊情况下,解析器会失败:

 Select Col1 as First_Name, Col2 as Last_Name, col3 as 2012_P_Customer
 From MyTable

将 Col3 解析为 2012_P_Customer 时,System.Linq.Dynamic 解析器失败。它不喜欢 2012 数字作为前缀。

当我将其更改为“col3 as P_Customer_2012”时,它运行良好。

我知道为 SQL 列添加前缀是一种不好的做法,但我不知道这对于列别名是否有效。

于 2013-05-24T15:24:38.670 回答