我使用SDK处理从Staging
到Microsoft Dynamic CRM
的数据迁移我遇到了有关速度性能的问题。
我对搜索现有数据使用List<>
和SQL Query
的效果存在疑问。
我的问题是
List<>
和Query from DataBase
中的现有数据之间
逐行加快(列表中的约100,000个对象或
数据库中的100,000记录)如果使用此方法,请立即连接数据库。index
应该比在Object中搜索更快
列表对吗?但如果我使用Query搜索现有数据(100,000
记录)它必须打开并查询100,000次谢谢。
答案 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];
}