This article is a mirror article of machine translation, please click here to jump to the original article.

View: 20726|Reply: 0

[Source] Differences between .net IQueryable and IList

[Copy link]
Posted on 8/22/2016 11:22:07 AM | | |

IList (IList<T>) immediately creates persistent data in memory, which does not implement "deferred execution", and if the loaded entity has associated entities, the associated entity will not be loaded (neither immediately nor lazy).

IQeurable <T>does not immediately create persistent data in memory, but only loads data into memory if it is traversed (e.g. through forreach), converted to a list, etc., and can achieve "deferred execution", if the currently loaded entity has associations, this associated entity can be loaded by the next access.

Look at the following piece of code:
//IList的情况
IList users = res. ToList(); Users have been loaded into memory, but the associated entity (UserInfos) for each user has not
                       is loaded, so the next line of code doesn't go through smoothly
var ss = users. Where(p => p.UserInfos.ID != 3); Error is reported here because P's UserInfos entity cannot be loaded

IQuerable's situation
IQueryable users = res. AsQueryable(); users are not loaded immediately, and the associated entity can be obtained by "lazy loading"
                                   Got it
var ss = users. Where(p => p.UserInfos.ID != 3); The corresponding SS was successfully obtained here




Previous:.net does WeChat development to obtain user information and scan function [with source code]
Next:Ask for an Alipay order monitoring discuz use, @小渣渣
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com