Reputation: 3945
Is this returning an IEnumerable
or an IQueryable
?
public IEnumerable<OrderRecord> GetAll()
{
return _repository.Table.Where(x => x.ClientAccount.Id == _userSession.GetCurrentClientAccount()).AsEnumerable();
}
Then, using breakpoint @ the IEnumerable
, doesn't it return an IEnumerable
?
Why does it say Queryable
in the NHibernate.Linq.NhQuerable
(first line of the debug)?
Upvotes: 0
Views: 222
Reputation: 38130
It returns an object of type Nhibernate.Link.NhQueryable<ACCS.StockControl.Models.OrderRecord>
.
That type happens to implement the IQueryable<ACCS.StockControl.Models.OrderRecord>
, IEnumerable<ACCS.StockControl.Models.OrderRecord>
, and IEnumerable
interfaces.
Upvotes: 1
Reputation: 84734
NhQueryable<T>
implements both IQueryable<T>
and IEnumerable<T>
.
By calling AsEnumerable()
, you now have access to the IEnumerable<T>
methods which will, for example, run additional LINQ methods like Where
and Select
from an in-memory collection after the original IQueryable<T>
query has been executed in the database.
Upvotes: 3
Reputation: 125620
It returns something, that implements IEnumerable<T>
. That fact that at the same time that thing implements IQueryable<T>
doesn't matter.
The same applies to e.g. following situation:
public ICollection<string> GetCollection()
{
return new List<string>();
}
if you try to check what is returned from GetCollection
you'll get actual class name, List<string>
in that example. But because method signature states that it returns ICollection<T>
you'll get only access to methods/properties exposed by ICollection<T>
interface (ofc. unless you explicitly cast it back to List<string>
).
Upvotes: 7