نوشته شده توسط
adinochestva
IQueryable معمولا استفاده از بانک های اطلاعاتی هست و IEnumerable برای دسترسی به داده در حافظه.
وقتی شما حلقه ای را استفاده می کنید با IEnumerable<T> در هر چرخش فقط یک ردیف بازگردانده می شه و به قولی پلیه ای عمل می کند ولی دستوری که IQueryable<T> بر می گردونه Late binding هست به این معنا که در اولین مورد استفاده تمام ردیف ها از مبدا گرفته شده و اولین ردیف به شما تحویل می شود
در کل مبدا اطلاعات هست که این دو را جدا می کند.
سلام ،
ممنون دوست عزيز ، و لي اگر من منظور شما رو درست متوجه شده باشم ، حرف شما با گفته Scott Guttrie در منافات است :
One of the nice characteristics of IEnumerable<T> interfaces is that objects that implement them can defer the actual execution of the queries until a developer first attempts to iterate over the values (this is accomplished using the "yield" construct that was first introduced with C# 2.0 in VS 2005). LINQ and query syntax expressions take advantage of this feature, and defer the actual execution of queries until the first time you loop over the results. If you never iterate over the IEnumerable<T> result, then the query is never executed.
For example, consider the below LINQ to SQL example:
The database will be hit and the values to populate our Category objects will be retrieved not when the query syntax expression is declared - but rather when we first try and loop over the results (indicated above with the red arrow).
همانطور كه ملاحظه ميكنيد حتي هنگام استفاده از IEnumerable<t> نيز تا هنگامي كه برنامه نويس داخل IEnumerable پيمايش نكند كوئري انجام نميشود .
( البته اگر منظور شما از LateBinding تاخير در اجراي كوئري باشد ، در غير اينصورت لطف كنيد و در اين مورد بيشتر توضيح دهيد )