0
votes

In my code I allow the user to filter by a parameter (extensions). There can be quite a lot of different extensions (100+).

Until now I used this:

foreach (var i in FilteredExt)
{
    backupEvents = backupEvents.Where(e => (e.Ext != i && e.Ext != "." + i));
}

But I noticed that this works if FilteredExt contains small amount of items (~30) - if it contains more the query breaks and the view is left empty.

Error:

parser stack overflow at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain) at System.Data.SQLite.SQLiteCommand.BuildNextCommand() at System.Data.SQLite.SQLiteDataReader.NextResult() at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave) at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func3 operation, TInterceptionContext interceptionContext, Action3 executing, Action3 executed) at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext) at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) --- End of inner exception stack trace --- at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues) at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass7.b__5() at System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() at System.Data.Entity.Internal.LazyEnumerator1.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

Is there a way to handle/avoid this?

1
Any reason the FilteredExt arent stored in the Database?Rand Random
@RandRandom mainly because I never thought about it. You're suggesting adding a new table and updating it everytime user de/selects extensions? I guess this isn't a problem - but how then I get events without FilteredExt ?Maverick Meerkat
var backupevents = context.Events.SqlQuery("select * from events ev where ev.ext not in (select fe.ext from filteredext fe)"); - dont know how to translate not in to linq, but you could use it.Rand Random
This is a good suggestion. I will try to implement this when I have time. I wonder in cases of filtering - does it usually works with saving the filtered list in the DB or do you usually save it in the runtime environment?Maverick Meerkat

1 Answers

1
votes

Im not sure will it work or not, but can you try to do filtering in that way:

var FilteredExtWithDot = FilteredExt.Select(x=>"." + x).ToArray();
backupEvents = 
          backupEvents
          .Where(e => !FilteredExt.Contains(e.Ext) && !FilteredExtWithDot.Contains(e.Ext));

and no foreach needed.