迟来的零碎笔记

1.

请教个问题:
楼主文中说“因为 IQueryable 是延迟查询,只有在执行 AsEnumerable 的时候,才会真正去查询”。
我调试程序过程中,在单步执行AsEnumerable()时,使用SQL Server Profiler并没有检测到有sql语句执行...
#107楼[楼主] 2015-08-28 18:43 田园里的蟋蟀  
@_天光云影
嗯,我测试了下,确实没有执行SQL,需要ToList,或者FirstOrDefault,说明:

Calling AsEnumerable() does not guarantee that the results will be executed immediately.
IQueryable is the interface that allows LINQ to SQL to perform its magic. IQueryable implements IEnumerable so when you call AsEnumerable(), nothing really happens.
To force query execution, you must call ToList().

来自:Am I misunderstanding LINQ to SQL .AsEnumerable()?
原文地址:https://www.cnblogs.com/x-poior/p/5231467.html