列表中的搜索之间的性能<>和查询

时间:2016-08-31 11:39:57

标签: c# performance dynamics-crm

我使用SDK处理从StagingMicrosoft Dynamic CRM的数据迁移我遇到了有关速度性能的问题。

我对搜索现有数据使用List<>SQL Query的效果存在疑问。

我的问题是

  1. 在搜索List<>Query from DataBase中的现有数据之间 逐行加快(列表中的约100,000个对象或 数据库中的100,000记录)如果使用此方法,请立即连接数据库。
  2. 我认为DataBase使用index应该比在Object中搜索更快 列表对吗?但如果我使用Query搜索现有数据(100,000 记录)它必须打开并查询100,000次
  3. 谢谢。

1 个答案:

答案 0 :(得分:1)

示例(显然你想要优化它 - 它只是一个想法):

private Dictionary<string, HashSet<person>> peopleList = new Dictionary<string, HashSet<person>>();
    public void loadPeople()

    {
        List<person> people = new List<person>();
        people.Add(new person() { firstName = "Shirley", lastName = "Kotarski", age = 45 });
        people.Add(new person() { firstName = "Bob", lastName = "Smith", age = 24 });
        people.Add(new person() { firstName = "Bill", lastName = "Jones", age = 32 });
        people.Add(new person() { firstName = "Jim", lastName = "Hostettler", age = 19 });
        people.Add(new person() { firstName = "Ralph", lastName = "Billings", age = 27 });
        people.Add(new person() { firstName = "Eddir", lastName = "Johnson", age = 58 });
        for (int i = 65; i < 91; i++)
        {//Partitions based on first letter of first name
            string charI = ((char)i).ToString();
            string key = charI;
            peopleList.Add(key, new HashSet<person>(people.Where(p => p.firstName.Substring(0, 1) == charI).ToArray()));

        }
    }
    public void processListOfPeople()
    {
        for (int i = 65; i < 91; i++)
        {
            string charI = ((char)i).ToString();
            string key = charI;
            List<person> people = peopleList[key].ToList();
         }
    }
    public person lookupPerson(string firstName)
    {
        person p = new so_Win.person();
        string key = firstName.Substring(0, 1);
        return peopleList[key].Where(m => m.firstName == firstName).ToArray()[0];
    }