linq怎么提高查询效率


linq如何提高查询效率

ItemProp是一个类;itemProps 有几百万条数据,现在这样查,一秒钟大概只能构造一百条itemProp ,请问要怎么提高效率呢?

  List<ItemProp> itemProps = this.GetItemProps(dir);
   List<ItemProp> newProps = new List<ItemProp>();
   DataTable dtPid = DB.GetDataSet("select AttributeId,CategoryId from erp.dbo.Category2Attributes", DB.DataBase.ERPDBSlave).Tables[0];
               foreach (DataRow row in dtPid.Rows)
                {
                    long pid = long.Parse(row["AttributeId"].ToString());
                    long cid = long.Parse(row["CategoryId"].ToString());
                    ItemProp itemProp = (from a in itemProps
                                         where a.Cid == cid && a.Pid == pid
                                         select a).FirstOrDefault();
                    newProps.Add(itemProp);
                }
                newProps = itemProps.Except(newProps).ToList();


.net 程序开发 linq

黑zero银 12 years, 2 months ago

用HASHSET。


1: 先把数据库里所有的东东弄出来,SELECT ID ONLY, 然后放入HASHSET。(注意别用.ToList()),用ienumerable)

不可名状D月 answered 12 years, 2 months ago

Your Answer