is it possible to add an extension method to IQueryable<T> and then, for my Linq2Sql or EF or NHibernate or LinqToObjects, define it’s functionality / how each repository will impliment this method / translate this method to some sql?
For example, imagine I want the following :-
var result = (from q in db.Categories()
where q.IWishIKnewHowToCode("hi")
select q).ToList();
now, the code for the extension method IWishIKnewHowToCode() will differ when it’s L2S, compared to EF or LinqToObjects, etc.
I’m not talking about a Pipes and Filters, here. That I know how to do that.
So imagine that, if this was L2S, then that method would do a linq Where clause but if the repository was .. say … LinqToObjects, it would do a Take(10).
Is this possible?
(I’m not too sure what it’s officially called … about what I’m wanting to do)
That is pretty evil, but the closest I can think would be to special-case the provider:
(obviously there are other ways to switch on
Type).Then use via fluent syntax (not query syntax):