我有这个
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:
答案 0 :(得分:5)
看起来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_, ...