static public IEnumerable <Key> Where <Key>(this BTreeBase <Key, Key> sourceCollection, Expression <Func <Key, bool> > expr)
#if WINDOWS_PHONE
            where Key : new()
#endif
        {
            if (sourceCollection != null)
            {
                bool                 noIndex  = true;
                SessionBase          session  = sourceCollection.Session;
                CompareByField <Key> comparer = sourceCollection.Comparer as CompareByField <Key>;
                BinaryExpression     binExp   = expr.Body as BinaryExpression;
                if (binExp != null && canUseIndex <Key>(sourceCollection, binExp, comparer))
                {
                    session.WaitForIndexUpdates();
                    switch (expr.Body.NodeType)
                    {
                    case ExpressionType.AndAlso:
                    {
                        noIndex = AndUseIndex(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in And <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                        else
                        {
                            BinaryExpression leftExpr = (BinaryExpression)binExp.Left;
                            binExp = leftExpr;
                            switch (binExp.NodeType)
                            {
                            case ExpressionType.Equal:
                            {
                                noIndex = EqualUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> equal  = Equal <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result = equal.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }

                            case ExpressionType.LessThan:
                            {
                                noIndex = LessThanUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> lessThan = LessThan <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result   = lessThan.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }

                            case ExpressionType.LessThanOrEqual:
                            {
                                noIndex = LessThanOrEqualUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> lessThan = LessThanOrEqual <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result   = lessThan.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }

                            case ExpressionType.GreaterThan:
                            {
                                noIndex = GreaterThanUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> greaterThan = GreaterThan <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result      = greaterThan.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }

                            case ExpressionType.GreaterThanOrEqual:
                            {
                                noIndex = GreaterThanOrEqualUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> greaterThan = GreaterThanOrEqual <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result      = greaterThan.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }
                            }
                            ;
                        }
                    }
                    break;

                    case ExpressionType.Equal:
                    {
                        noIndex = EqualUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in Equal <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;

                    case ExpressionType.GreaterThan:
                    {
                        noIndex = GreaterThanUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in GreaterThan <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;

                    case ExpressionType.GreaterThanOrEqual:
                    {
                        noIndex = GreaterThanOrEqualUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in GreaterThanOrEqual <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;

                    case ExpressionType.LessThan:
                    {
                        noIndex = LessThanUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in LessThan <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;

                    case ExpressionType.LessThanOrEqual:
                    {
                        noIndex = LessThanOrEqualUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in LessThanOrEqual <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;
                    }
                }
                if (noIndex) //no index?  just do it the normal slow way then...
                {
                    IEnumerable <Key> sourceEnum;
                    if (sourceCollection.UsesOidShort)
                    {
                        BTreeSetOidShort <Key> c = (BTreeSetOidShort <Key>)sourceCollection;
                        sourceEnum = c.AsEnumerable <Key>();
                    }
                    else
                    {
                        BTreeSet <Key> c = (BTreeSet <Key>)sourceCollection;
                        sourceEnum = c.AsEnumerable <Key>();
                    }
                    IEnumerable <Key> result = sourceEnum.Where <Key>(expr.Compile());
                    foreach (Key resultItem in result)
                    {
                        yield return(resultItem);
                    }
                }
            }
        }