Print Page | Close Window

Custom filter methods in LINQ statement

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1310
Printed Date: 24-May-2025 at 3:37am


Topic: Custom filter methods in LINQ statement
Posted By: philcockfield
Subject: Custom filter methods in LINQ statement
Date Posted: 07-Jun-2009 at 8:36pm
I'm building out a PersitenceService as per the example in the PrismExplorer.

I have a query that looks like this:

   query = Manager.People
          .Where(p => p.LastName.ContainsAny("smith bell", " "));


The 'ContainsAny' is my own extension method. DevForce is throwing errors saying it can't find it, which makes sense as it's probably not the same assembly name on the server. An alternative I tried was putting this 'ContainsAny' as a static method on the [Person] object itself, which IS shared between the SL client and the server.

This then caused DevForce to throw an Linq exception saying it could not execute the method.

So my question is, what is the approach for calling out to custom filter routines within a LINQ statement?

Thanks!
---
Phil



Replies:
Posted By: eileenv
Date Posted: 18-Jun-2009 at 11:14am
Unfortunately, custom filter routines/custom extension methods, etc. are not supported by the Entity Framework's LINQ to Entities. This was taken from a blog ( http://mosesofegypt.net/post/LINQ-to-Entities-what-is-not-supported.aspx - http://mosesofegypt.net/post/LINQ-to-Entities-what-is-not-supported.aspx ):
 
"By design, LINQ to Entities requires the whole LINQ query expression to be translated to a server query. Only a few uncorrelated subexpressions (expressions in the query that do not depend on the results from the server) are evaluated on the client before the query is translated. Arbitrary method invocations that do not have a known translation, like GetProducts() in this case, are not supported." - Diego Vega, a Program Manager at Entity Framework Team


Posted By: philcockfield
Date Posted: 18-Jun-2009 at 3:45pm
Damn! OK, thanks for looking into thie Eileen.



Print Page | Close Window