Dynamics CRM OrderBy 表达式不起作用
Dynamics CRM OrderBy expression not working
我正在尝试从 Dynamics CRM 下载线索 ID,我需要按 LeadId 排序:
IOrganizationService orgService = dynamicService.OrgService;
QueryExpression request = new QueryExpression()
{
EntityName = "lead",
ColumnSet = new ColumnSet("leadid"),
Criteria = new FilterExpression(),
PageInfo = new PagingInfo() { ReturnTotalRecordCount = true, Count = 50, PageNumber = 1 }
};
request.Orders.Add(new OrderExpression("leadid", OrderType.Ascending));
EntityCollection response = orgService.RetrieveMultiple(request);
foreach(Entity e in response.Entities)
{
Console.WriteLine($"{e.Attributes["leadid"]}");
}
但是,这是按随机顺序返回的。
b9b0f003-356d-e911-a966-000d3a1d7430
4298cdf4-4370-e911-a966-000d3a1d7430
97582b3c-2f6d-e911-a971-000d3a1d7b43
92d57a83-338f-e611-80e0-c4346bb588e8
a0d57a83-338f-e611-80e0-c4346bb588e8
a2d57a83-338f-e611-80e0-c4346bb588e8
a6d57a83-338f-e611-80e0-c4346bb588e8
我做错了什么?
根据 GUID sort algorithm.
正确排序
The comparison is made by looking at byte "groups" right-to-left, and left-to-right within a byte "group". A byte group is what is delimited by the '-' character. More technically, we look at bytes {10 to 15} first, then {8-9}, then {6-7}, then {4-5}, and lastly {0 to 3}.
所以 b9b0f003-356d-e911-a966-000d3a1d7430 小于 4298cdf4-4370-e911-a966-000d3a1d7430。
同样4298cdf4-4370-e911-a966-000d3a1d7430小于
97582b3c-2f6d-e911-a971-000d3a1d7b43.
以此类推
我正在尝试从 Dynamics CRM 下载线索 ID,我需要按 LeadId 排序:
IOrganizationService orgService = dynamicService.OrgService;
QueryExpression request = new QueryExpression()
{
EntityName = "lead",
ColumnSet = new ColumnSet("leadid"),
Criteria = new FilterExpression(),
PageInfo = new PagingInfo() { ReturnTotalRecordCount = true, Count = 50, PageNumber = 1 }
};
request.Orders.Add(new OrderExpression("leadid", OrderType.Ascending));
EntityCollection response = orgService.RetrieveMultiple(request);
foreach(Entity e in response.Entities)
{
Console.WriteLine($"{e.Attributes["leadid"]}");
}
但是,这是按随机顺序返回的。
b9b0f003-356d-e911-a966-000d3a1d7430
4298cdf4-4370-e911-a966-000d3a1d7430
97582b3c-2f6d-e911-a971-000d3a1d7b43
92d57a83-338f-e611-80e0-c4346bb588e8
a0d57a83-338f-e611-80e0-c4346bb588e8
a2d57a83-338f-e611-80e0-c4346bb588e8
a6d57a83-338f-e611-80e0-c4346bb588e8
我做错了什么?
根据 GUID sort algorithm.
正确排序The comparison is made by looking at byte "groups" right-to-left, and left-to-right within a byte "group". A byte group is what is delimited by the '-' character. More technically, we look at bytes {10 to 15} first, then {8-9}, then {6-7}, then {4-5}, and lastly {0 to 3}.
所以 b9b0f003-356d-e911-a966-000d3a1d7430 小于 4298cdf4-4370-e911-a966-000d3a1d7430。
同样4298cdf4-4370-e911-a966-000d3a1d7430小于 97582b3c-2f6d-e911-a971-000d3a1d7b43.
以此类推