What's the difference(s) between .ToList(), .AsEnumerable(), AsQueryable()?

后端 未结 4 2150
一向
一向 2020-11-22 16:41

I know some differences of LINQ to Entities and LINQ to Objects which the first implements IQueryable and the second implements IEnumerable and my

4条回答
  •  清歌不尽
    2020-11-22 17:19

    ToList() will being everything in memory and then you will be working on it. so, ToList().where ( apply some filter ) is executed locally. AsQueryable() will execute everything remotely i.e. a filter on it is sent to the database for applying. Queryable doesn't do anything til you execute it. ToList, however executes immediately.

    Also, look at this answer Why use AsQueryable() instead of List()?.

    EDIT : Also, in your case once you do ToList() then every subsequent operation is local including AsQueryable(). You can't switch to remote once you start executing locally. Hope this makes it a little bit more clearer.

提交回复
热议问题