Am I misunderstanding LINQ to SQL .AsEnumerable()?

前端 未结 5 660
遥遥无期
遥遥无期 2020-11-28 07:21

Consider this code:

var query = db.Table
              .Where(t => SomeCondition(t))
              .AsEnumerable();

int recordCount = query.Count();
int          


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 08:07

    Well, you are on the right track. The problem is that an IQueryable (what the statement is before the AsEnumerable call) is also an IEnumerable, so that call is, in effect, a nop. It will require forcing it to a specific in-memory data structure (e.g., ToList()) to force the query.

提交回复
热议问题