Reputation: 14831
I am working on a ASP.NET project. For interacting with database, I am using Entity Framework and LINQ. What I know is using IQueryable
is better than IEnumerable
If another query is going to be performed. But what I am wondering is, I have a repository and a method as below:
public IQueryable<Category> getData(){ return db.categories.AsQueryable(); }
As you can see above, I am doing type casting using AsQueryable in return statement whereas the function return type is IQueryable already. But I am doing it because I am not sure, if I call that function in Controller like repository.getData()
, will it be IQueryable
without type casting?
Can I remove AsQueryable()
type casting? Without it, will it be converted to IEnumerable
? Will that offer the same performance if I remove AsQueryable
?
Upvotes: 1
Views: 1338
Reputation: 34830
If db.categories
is derived from (or simply is) IQueryable<Category>
then yeah, sure, you can remove it.
Upvotes: 2