How to use or not to use FieldCompareSetPredicate

Posts   
 
    
gregkuha60
User
Posts: 47
Joined: 23-Jan-2012
# Posted on: 04-Dec-2013 12:04:44   

Hello

I have a List<int> containing my values for find my items with "FieldCompareSetPredicate ". Code snippet as follow. var logids = new List<int> (); May contain more than 3000 items. predicateExpression.Add (new FieldCompareSetPredicate (ProcessLogBinaryFields.LogId, null, ProcessLogBinaryFields.LogId, null, SetOperator.IN, ( ProcessLogBinaryFields.LogId == logids.ToArray () )));

This generates a "FIELD IN" with thousands of values for filtering with this error. Have i reach some kind of limit? "..

SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException was caught HResult=-2146232832 Message=An exception was caught during the execution of a retrieval query: A severe error occurred on the current command. The results, if any, should be discarded. A severe error occurred on the current command. The results, if any, should be discarded.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception. Source=SD.LLBLGen.Pro.ORMSupportClasses RuntimeBuild=10252013 RuntimeVersion=4.1.0.0 QueryExecuted= Query: SELECT FileName , ID AS Id , IDate AS Idate , IUser AS Iuser , LogBlobData , LogID AS LogId FROM ProcessLogBinary WHERE ProcessLogBinary.LogID IN (@p1, @p2, @p3, @p4, and continious more than 2000.

InnerException: System.Data.SqlClient.SqlException HResult=-2146232060 Message=A severe error occurred on the current command. The results, if any, should be discarded. A severe error occurred on the current command. The results, if any, should be discarded. Source=.Net SqlClient Data Provider ErrorCode=-2146232060 Class=11 LineNumber=0 Number=0 Procedure="" Server=fagusdb State=0 StackTrace: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 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) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) 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.ExecuteReader(CommandBehavior behavior) at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Query\RetrievalQuery.cs:line 109 InnerException:

.."

However, I could do a foreach on my list but then i have to do one read per item to the database instead of one.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 04-Dec-2013 17:48:19   

The SQL Command has a 2100 parameters limit. So I suggest you use a temp table to hold these values, and join to it, to filter the main query.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Dec-2013 07:25:03   

... or, instead of fetch them one by one, fetch them in batches of 2100 each.

David Elizondo | LLBLGen Support Team
gregkuha60
User
Posts: 47
Joined: 23-Jan-2012
# Posted on: 05-Dec-2013 09:58:45   

Hello and thanks for your help and attention.

I missed the thing that there is a limit for number of parameters.

Problem solved

best regards greg