我正在尝试获得这样的节点:
DocumentHelper.GetDocuments()
.Where("NodeParentID == 25 && NodeLevel == 2")
但出现异常:
“ =”附近的语法不正确。在 System.Data.SqlClient.SqlConnection.OnError(SqlException异常, 布尔值breakConnection,Action
1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource
1完成,Int32超时,任务和任务, 布尔值和usedCache,布尔值asyncWrite,布尔值inRetry) System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior,runBehavior,布尔值returnStream,字符串 方法) System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior 行为,String方法)在 System.Data.Common.DbDataAdapter.FillInternal(DataSet数据集, DataTable []数据表,Int32 startRecord,Int32 maxRecords,字符串 srcTable,IDbCommand命令,CommandBehavior行为)位于 System.Data.Common.DbDataAdapter.Fill(数据集dataSet,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand命令, CommandBehavior行为) System.Data.Common.DbDataAdapter.Fill(数据集dataSet)位于 CMS.DataEngine.AbstractDataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams,QueryTypeEnum queryType,布尔 requireTransaction)---内部异常堆栈跟踪的结尾---
在CMS.DataEngine.AbstractDataConnection.HandleError(String queryText, 例外) CMS.DataEngine.AbstractDataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams,QueryTypeEnum queryType,布尔 requireTransaction) CMS.DataEngine.GeneralConnection.RunQuery(QueryParameters query)在 CMS.DataEngine.GeneralConnection.RunQueryWithRetry(QueryParameters 查询,Int32 retryCount)位于 CMS.DataEngine.GeneralConnection.ExecuteQuery(QueryParameters查询, Int32&totalRecords)在 CMS.DataEngine.DataQueryBase1.GetDataFromDBInternal() at CMS.DataEngine.DataQueryBase
1.GetDataFromDB()在 CMS.DataEngine.DataQueryBase1.GetData() at CMS.DataEngine.DataQueryBase
1.get_Result()位于 CMS.DataEngine.DataQueryBase1.GetResults(IDataQuery query, Int32& totalRecords) at CMS.DataEngine.DataQueryBase
1.GetDataFromDB()
在 CMS.DocumentEngine.DocumentQueryProperties.GetDataInternal(IDocumentQuery 查询,例如,Func1 baseGetDataMethod, Action
1 setTotalRecords) CMS.DataEngine.DataQueryBase1.GetData() at CMS.DataEngine.DataQueryBase
1.get_Result()位于 CMS.DataEngine.MultiObjectQueryBase3.EnsureTypedResult() at CMS.DataEngine.MultiObjectQueryBase
3.GetEnumerator()在 System.Collections.Generic.List1..ctor(IEnumerable
1个集合)
在System.Linq.Enumerable.ToList [TSource](IEnumerable`1源)上
我在做什么错了?
答案 0 :(得分:2)
您的“ WHERE”子句中的SQL语法不正确。您正在尝试在需要使用T-SQL的地方使用C#语法
不正确:
DocumentHelper.GetDocuments().Where("NodeParentID == 25 && NodeLevel == 2");
正确:
DocumentHelper.GetDocuments().Where("NodeParentID = 25 AND NodeLevel = 2");
答案 1 :(得分:0)
==是一种c#语法,SQL仅使用一个=。
您应该执行以下条件:
.Where("NodeParentID", QueryOperator.Equals, 25)
.Where("NodeLevel ", QueryOperator.Equals, 7);