1

Here in docs of DbSet(TEntity) I did not find toList(). Why is that so although this method works when invoked on DbSet<TEntity> as instance method. Related code I found is:

Part of controller:

private MovieDBContext db = new MovieDBContext();

        // GET: /Movie/
        public ActionResult Index()
        {
            return View(db.Movies.ToList());
        }

DbContext class:

public class MovieDBContext : DbContext
    {
        public DbSet<Movie> Movies { get; set; }
    }
user3461957
  • 163
  • 2
  • 5
  • 14
  • You can use toList() on anything that returns iQueryable and iEnumerable. – Zach M. Jun 26 '14 at 20:51
  • possible duplicate of [What are Extension Methods?](http://stackoverflow.com/questions/403539/what-are-extension-methods) – Tetsujin no Oni Jun 26 '14 at 20:53
  • 2
    @ZachM. There is no `ToList` overload for `IQueryable`. There is only one for `IEnumerable`. `IQueryable` extends `IEnumerable`. – Servy Jun 26 '14 at 21:03
  • You can always right-click a member and click "Go to Definition" to see where it originates. You'll then see in what namespace the member is defined and from which assembly it is loaded (or go straight to the source file if it's in your project). – CodeCaster Jun 26 '14 at 21:11
  • Thank you, I was speaking generally. – Zach M. Jun 27 '14 at 13:37

1 Answers1

3

DbSet implements IEnumerable. ToList is an extension method available on any IEnumerable from the System.Linq.Enumerable class.

Within the IDE, you can tell something is an extension method by the icon and the fact that the first parameter uses the this keyword.

IDE screenshot

John Koerner
  • 37,428
  • 8
  • 84
  • 134