-1

Im trying to overwrite the behavior of the custom where clause to look at an index.

So I have a custom collection with a custom where method.

snippet..

public IndexedDbSet<T> : IdbSet<T>   // IdbSet<T> :  IQueryable<T>
{

  public IEnumerable<T> Where ( Expression<Func<T,bool>> predicate) `
  {
  }
}

Im calling it like this var blastNum = collection.Where( x => x.SiteId ==siteId).ToList();

however when i run a where on the collection it calls the extension method in corelib.

I have tried returning IQueryable as well..

Is this behavior expected ? Is there a better way ?

Note i have an existing code base that does a lot of LINQ to a DB however i need it to go to memory and for 1M+ records brute force takes too long. Its a Windows Store app.

Note not the same as order of precedence on interface because i'm calling it directly not the interface ,its LINQ that maybe changing the behavior.

user1496062
  • 1,309
  • 1
  • 7
  • 22
  • 1
    Where is your code for that ? – Mahesh Mar 18 '15 at 03:19
  • 2
    Can you please post the class where you have your custom `Where` and the code where you're using it. Unless the very first call in a LINQ chain is the `Where`, your custom `Where` will not be called, since LINQ methods return `IEnumerable`. – Asad Saeeduddin Mar 18 '15 at 03:23
  • No because i'm calling it directly not the interface its LINQ that maybe changing the behavior. – user1496062 Mar 18 '15 at 04:03
  • 1
    @user1496062 Could you also show where you get the `collection` reference? The point is to find out what the type of the reference is against which you invoke `Where`. – Asad Saeeduddin Mar 18 '15 at 04:13
  • This was incorrect .. the property was set but the whole context was accessed through an interface – user1496062 Mar 18 '15 at 23:17

1 Answers1

-1

Based on the details you provided, I think the class from where you are invoking the 'Where' method has 'System.Linq' namespace in usings. So, it invokes the 'Where' method in .NET Framework rather than from your class.

If you don't need System.Linq namespace then remove it to fix the issue or change your 'Where' method to static and accept object as one of the parameter as follows and apply your predicate on that object

public static IEnumerable<T> Where ( customCollection instance, Expression<Func<T,bool>> predicate)
kodebot
  • 1,718
  • 1
  • 22
  • 29
  • Yes it does have System.Linq but this is needed for the existing code base that uses EF. I do have a custom Idbset though,, I can put an extention method on the class for the where but not sure if it would pick it up. – user1496062 Mar 18 '15 at 03:44
  • My suggestion is to change the method to static or rename it to something that won't conflict with existing methods. – kodebot Mar 18 '15 at 03:46
  • but the goal is for the EF code ( about 200K lines) to still work .. a static would mean a huge amount of #if #else... I still dont know why its not calling Where i thought instance methods were preferred over extension. – user1496062 Mar 18 '15 at 03:51
  • check the comment from @nintendojunkie to understand the precedence – kodebot Mar 18 '15 at 03:59
  • Nope not the same because im directly calling the collection not via an interface. Though Linq maybe doing something strange ,. – user1496062 Mar 18 '15 at 04:05
  • could you share the definition of you custom collection? – kodebot Mar 18 '15 at 04:07