You're returning the same type (IQueryable<T1>
) that you have in your original queryable, so your extension method is taking an IQueryable<foo>
and returning an IQueryable<foo>
, where you want to return an IQueryable<bar>
. Also, you define T2 as a generic type parameter, but not T1. You could change to this:
public static IQueryable<T2> Convert<T1, T2>(IQueryable<T1> source) where T1 : class
{
...
}
Then invoke like so:
IQueryable<Bar> result = source.Convert<Foo, Bar>();
But.. as Jon points out, this could be done in a Select. If the conversion between foo
and bar
is not so trivial, or you want to re-use it, you could define that mapping, rather than converting an IQueryable to IQueryable.