Return IQueryable<T> as IEnumerable<T> will cause in database call?

I use Entity Framework. Let's say I have a method:

public IEnumerable<User> GetUsers() // return IEnumerable<User>
{
    using (var context = new AppDbContext())
    {
        return context.Users;
    }
}

Now when I call:

var users = GetUsers();

Will this operation perform a database query or not?

Jon Skeet
people
quotationmark

Not if you don't do anything with it, no.

However, if you try to iterate over the results (or call Count() etc) then it will try to make a database call... and I'd expect it to then fail, because you've disposed of the context at that point.

people

See more on this question at Stackoverflow