Question

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)?

Was it helpful?

Solution

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>).

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top