views:

60

answers:

1

I have:

  • a stored procedure which retrieves zip codes in a radius around another zip code

  • a table with contacts

I'm getting the contacts through an IQueryable interface which I've extended with various extension methods to filter results by age etc.

What I have trouble with is adding an IQueryable extension method which calls the stored procedure described above (zip codes in radius) and then joins those zip codes with my IQueryable list of contacts.

Any idea how to do this?

A: 

To do that, you would need to swap the sp for a udf. This is usually possible without impacting any existing code (that calls the SP) by simply forwarding the (existing) sp to the (new) udf, i.e.

CREATE PROC foo @blah int
AS
BEGIN
    SELECT * FROM dbo.foo_udf(@blah)
END

LINQ-to-SQL supports composability against udfs, but not SPs, so you should then be able to join to the UDF (via yourContext.UdfName(...)) in your query.

Marc Gravell
How do I access the data context from my IQueryable extension method to call the SP or UDF?
Alex
@Alex - the the `IQuerable<T>`? You wouldn't. I would probably make it an input *to* the extension method. But with the existing SP approach you simply **can't** join them (at the db, at least, which is the implicit desire)
Marc Gravell