NHibernate.Exceptions.GenericADOException 为什么?

发布于 2024-10-25 06:17:32 字数 6403 浏览 1 评论 0原文

我有这个

  return session.Query<CoursePermission>().Where(x => x.Student.StudentId == studentId).ToList();

我明白了

NHibernate.Exceptions.GenericADOException was unhandled by user code
  Message=could not execute query
[ select courseperm0_.PermissionId as Permissi1_3_, courseperm0_.Owner as Owner3_, courseperm0_.Add as Add3_, courseperm0_.Edit as Edit3_, courseperm0_.Delete as Delete3_, courseperm0_.View as View3_, courseperm0_.StudentId as StudentId3_, courseperm0_.CourseId as CourseId3_ from CoursePermissions courseperm0_ where courseperm0_.StudentId=@p0 ]
  Name:p1 - Value:757f27a2-e997-44f8-b2c2-6c0fd6ee2c2f
[SQL: select courseperm0_.PermissionId as Permissi1_3_, courseperm0_.Owner as Owner3_, courseperm0_.Add as Add3_, courseperm0_.Edit as Edit3_, courseperm0_.Delete as Delete3_, courseperm0_.View as View3_, courseperm0_.StudentId as StudentId3_, courseperm0_.CourseId as CourseId3_ from CoursePermissions courseperm0_ where courseperm0_.StudentId=@p0]
  Source=NHibernate
  SqlString=select courseperm0_.PermissionId as Permissi1_3_, courseperm0_.Owner as Owner3_, courseperm0_.Add as Add3_, courseperm0_.Edit as Edit3_, courseperm0_.Delete as Delete3_, courseperm0_.View as View3_, courseperm0_.StudentId as StudentId3_, courseperm0_.CourseId as CourseId3_ from CoursePermissions courseperm0_ where courseperm0_.StudentId=@p0
  StackTrace:
       at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
       at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
       at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
       at NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters)
       at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters)
       at NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results)
       at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results)
       at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters)
       at NHibernate.Impl.ExpressionQueryImpl.List()
       at NHibernate.Linq.NhQueryProvider.ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery)
       at NHibernate.Linq.NhQueryProvider.Execute(Expression expression)
       at NHibernate.Linq.NhQueryProvider.Execute[TResult](Expression expression)
       at Remotion.Data.Linq.QueryableBase`1.GetEnumerator()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at PermissionLevelRepo.GetPermission(Guid studentId) line 28
       at For(String email) in :line 63
       at (String email) in :line 50
       at PlannerController.Tab() :line 43
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
  InnerException: System.Data.SqlClient.SqlException
       Message=Incorrect syntax near the keyword 'Add'.
       Source=.Net SqlClient Data Provider
       ErrorCode=-2146232060
       Class=15
       LineNumber=1
       Number=156
       Procedure=""
       Server=mssql.frostyserver.com
       State=1
       StackTrace:
            at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
            at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
            at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
            at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
            at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
            at System.Data.SqlClient.SqlDataReader.get_MetaData()
            at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
            at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
            at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
            at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
            at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
            at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
            at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
            at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
            at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session)
            at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
            at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
            at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
       InnerException: 

I have this

  return session.Query<CoursePermission>().Where(x => x.Student.StudentId == studentId).ToList();

I get this

NHibernate.Exceptions.GenericADOException was unhandled by user code
  Message=could not execute query
[ select courseperm0_.PermissionId as Permissi1_3_, courseperm0_.Owner as Owner3_, courseperm0_.Add as Add3_, courseperm0_.Edit as Edit3_, courseperm0_.Delete as Delete3_, courseperm0_.View as View3_, courseperm0_.StudentId as StudentId3_, courseperm0_.CourseId as CourseId3_ from CoursePermissions courseperm0_ where courseperm0_.StudentId=@p0 ]
  Name:p1 - Value:757f27a2-e997-44f8-b2c2-6c0fd6ee2c2f
[SQL: select courseperm0_.PermissionId as Permissi1_3_, courseperm0_.Owner as Owner3_, courseperm0_.Add as Add3_, courseperm0_.Edit as Edit3_, courseperm0_.Delete as Delete3_, courseperm0_.View as View3_, courseperm0_.StudentId as StudentId3_, courseperm0_.CourseId as CourseId3_ from CoursePermissions courseperm0_ where courseperm0_.StudentId=@p0]
  Source=NHibernate
  SqlString=select courseperm0_.PermissionId as Permissi1_3_, courseperm0_.Owner as Owner3_, courseperm0_.Add as Add3_, courseperm0_.Edit as Edit3_, courseperm0_.Delete as Delete3_, courseperm0_.View as View3_, courseperm0_.StudentId as StudentId3_, courseperm0_.CourseId as CourseId3_ from CoursePermissions courseperm0_ where courseperm0_.StudentId=@p0
  StackTrace:
       at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
       at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
       at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
       at NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters)
       at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters)
       at NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results)
       at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results)
       at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters)
       at NHibernate.Impl.ExpressionQueryImpl.List()
       at NHibernate.Linq.NhQueryProvider.ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery)
       at NHibernate.Linq.NhQueryProvider.Execute(Expression expression)
       at NHibernate.Linq.NhQueryProvider.Execute[TResult](Expression expression)
       at Remotion.Data.Linq.QueryableBase`1.GetEnumerator()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at PermissionLevelRepo.GetPermission(Guid studentId) line 28
       at For(String email) in :line 63
       at (String email) in :line 50
       at PlannerController.Tab() :line 43
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
  InnerException: System.Data.SqlClient.SqlException
       Message=Incorrect syntax near the keyword 'Add'.
       Source=.Net SqlClient Data Provider
       ErrorCode=-2146232060
       Class=15
       LineNumber=1
       Number=156
       Procedure=""
       Server=mssql.frostyserver.com
       State=1
       StackTrace:
            at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
            at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
            at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
            at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
            at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
            at System.Data.SqlClient.SqlDataReader.get_MetaData()
            at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
            at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
            at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
            at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
            at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
            at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
            at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
            at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
            at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session)
            at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
            at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
            at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
       InnerException: 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囍孤女 2024-11-01 06:17:33

看起来 StudentId 是一个 Guid。尝试:

return session
  .Query<CoursePermission>()
  .Where(x => x.Student.StudentId.Equals(studentId))
  .ToList();

编辑:内部异常:

Message=Incorrect syntax near the keyword 'Add'

生成的 sql 有一个名为 Add 的列,尝试在映射规则中重命名它。

select courseperm0_.PermissionId as Permissi1_3_, courseperm0_.Owner as Owner3_, courseperm0_.Add as Add3_, ...

Looks like StudentId is a Guid. Try:

return session
  .Query<CoursePermission>()
  .Where(x => x.Student.StudentId.Equals(studentId))
  .ToList();

EDIT: The inner exception:

Message=Incorrect syntax near the keyword 'Add'

The generated sql has a column called Add, try renaming this in your mapping rules.

select courseperm0_.PermissionId as Permissi1_3_, courseperm0_.Owner as Owner3_, courseperm0_.Add as Add3_, ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文