在我的代码中,我允许用户按参数(扩展名)进行过滤。可以有很多不同的扩展(100 +)。
到现在为止我用过这个:
foreach (var i in FilteredExt)
{
backupEvents = backupEvents.Where(e => (e.Ext != i && e.Ext != "." + i));
}
但是我注意到,如果FilteredExt包含少量项目(~30),这是有效的 - 如果它包含更多的查询中断并且视图保持为空。
错误:
解析器堆栈溢出 System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn,String strSql,SQLiteStatement previous,UInt32 timeoutMS,String& strRemain) 在System.Data.SQLite.SQLiteCommand.BuildNextCommand()at System.Data.SQLite.SQLiteDataReader.NextResult()at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior表现在 System.Data.SQLite.SQLiteCommand.ExecuteReader(的CommandBehavior 行为) System.Data.Entity.Infrastructure.Interception.InternalDispatcher
1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func
3操作,TInterceptionContext interceptionContext, 行动3 executing, Action
3已执行) System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(的DbCommand 命令,DbCommandInterceptionContext interceptionContext)at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior行为) ---内部异常堆栈跟踪结束---在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](Func键1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectQuery
1<> c__DisplayClass7.b__5() 在System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable
1 forMergeOption)at System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() at System.Data.Entity.Internal.LazyEnumerator
1.MoveNext()at System.Collections.Generic.List1..ctor(IEnumerable
1集合)at System.Linq.Enumerable.ToList [TSource](IEnumerable`1 source)
有办法处理/避免这种情况吗?
答案 0 :(得分:1)
我不确定它是否有效,但您可以尝试以这种方式进行过滤:
var FilteredExtWithDot = FilteredExt.Select(x=>"." + x).ToArray();
backupEvents =
backupEvents
.Where(e => !FilteredExt.Contains(e.Ext) && !FilteredExtWithDot.Contains(e.Ext));
并且不需要foreach。