Entity Framework Queryable async

后端 未结 3 1805
悲&欢浪女
悲&欢浪女 2020-11-30 17:43

I\'m working on some some Web API stuff using Entity Framework 6 and one of my controller methods is a \"Get All\" that expects to receive the contents of a table from my da

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 17:56

    Long story short,
    IQueryable is designed to postpone RUN process and firstly build the expression in conjunction with other IQueryable expressions, and then interprets and runs the expression as a whole.
    But ToList() method (or a few sort of methods like that), are ment to run the expression instantly "as is".
    Your first method (GetAllUrlsAsync), will run imediately, because it is IQueryable followed by ToListAsync() method. hence it runs instantly (asynchronous), and returns a bunch of IEnumerables.
    Meanwhile your second method (GetAllUrls), won't get run. Instead, it returns an expression and CALLER of this method is responsible to run the expression.

提交回复
热议问题