千万别这么用linq,超级慢

来源:互联网 发布:网络赚钱兼职正规小虎 编辑:程序博客网 时间:2024/05/17 05:17

为什么linq这么慢,是不是你们这么用了。。。。


且看我的以前错误的例子

List<Custom> lstCus = XMain.GetCustomList();var linq = from _cus in lstCus           from _item in dc.Items           from _log in dc.LogBook           where _cus.RelatedID = _item.RelatdID .....            ...........   

各位看官猜执行了多少秒,30秒整整。。。。


优化之后

List<int> lstRid = lstCus.where(x=>x.ModuleID == 8).Select(x=>x.RelatedID).ToList();var linq =            from _item in dc.Items           from _log in dc.LogBook           where lstRid.Contain( _item.RelatdID) .....            ...........  


恩,优化之后执行时间是1两毫秒

原创粉丝点击