views:

746

answers:

1

I have an entity object 'User' which implements 'IUser':

IQueryable<User> users = Db.User;
return users;

But what I actually want to return is:

IQueryable<IUser>

So what is the best way to convert

IQueryable<User>

to

IQueryable<IUser>

without actually running the query? Right now I am doing this but it seems like a hack:

IQueryable<IUser> users = Db.User.Select<User, IUser>(u => u);
+2  A: 

Your "hacky" solution looks fine to me.

Craig Stuntz
Your correct. I just did a quick test. (+1)
bruno conde
I just tried that with the following exception:The 'TypeAs' expression with an input of type 'Bla.User' and a check of type 'Bla.IUser' is not supported. Only entity types and complex types are supported in LINQ to Entities queries.
Mike Comstock
Thanks for the test. I'll remove the alternative.
Craig Stuntz
Thanks for the speedy responses Craig!
Mike Comstock