【发布时间】:2012-09-21 10:25:57
【问题描述】:
根据this 问题(没有场景/示例;你应该删除它,我不能)这是我的问题:
我注意到,如果我在集合Attachment[] 之间执行Union,而不是Intersect,则项目的顺序“可以”改变。
这是我的代码:
GalleryDataClassesDataContext db = new GalleryDataClassesDataContext();
List<Attachment> Allegati = db.ExecuteQuery<Attachment>("EXEC SelectAttachmentsByKey @Key={0}, @IDCliente={1}", new object[] { "", "47" }).ToList();
List<Attachment> AllegatiPerCategorie = new List<Attachment>();
AllegatiPerCategorie = AllegatiPerCategorie.Union(db.AttachmentAttachmentCategories.Where(aac => aac.IDAttachmentCategory == 72).OrderBy(p => p.Ordine == null ? 1 : 0).ThenBy(p => p.Ordine).Select(aac => aac.Attachment)).ToList();
Allegati = Allegati.Intersect(AllegatiPerCategorie).ToList();
count = 0;
foreach (Attachment a in AllegatiPerCategorie)
{
Response.Write(count.ToString() + " - " + a.IDAttachment + "<br />");
count++;
}
Response.Write("<br />### FILTERED ###<br /><br />");
count = 0;
foreach (Attachment a in Allegati)
{
Response.Write(count.ToString() + " - " + a.IDAttachment + "<br />");
count++;
}
输出是:
0 - 6769
1 - 6792
2 - 6771
3 - 6699
4 - 6632
5 - 6774
6 - 6595
7 - 6602
8 - 6641
9 - 6643
10 - 6764
11 - 6634
12 - 6642
13 - 6660
14 - 6640
15 - 6665
16 - 6673
17 - 6767
18 - 6772
19 - 6766
20 - 6763
21 - 6768
22 - 6644
23 - 6635
24 - 6633
25 - 6793
26 - 6677
27 - 6608
28 - 6610
29 - 6558
30 - 6563
31 - 6631
32 - 6604
33 - 6606
34 - 6607
35 - 6596
36 - 6597
37 - 6598
38 - 6599
39 - 6600
40 - 6471
41 - 6470
42 - 6469
43 - 6601
44 - 6603
45 - 6663
46 - 6664
47 - 6645
48 - 6637
49 - 6638
50 - 6609
51 - 6611
52 - 6612
53 - 6613
54 - 6614
55 - 6615
56 - 6616
57 - 6617
58 - 6618
59 - 6619
60 - 6620
61 - 6622
62 - 6567
63 - 6568
64 - 6569
65 - 6570
66 - 6571
67 - 6572
68 - 6573
69 - 6575
70 - 6576
71 - 6577
72 - 6579
73 - 6580
74 - 6581
75 - 6582
76 - 6583
77 - 6584
78 - 6585
79 - 6586
80 - 6587
81 - 6588
82 - 6589
83 - 6590
84 - 6591
85 - 6592
86 - 6593
87 - 6594
88 - 6765
### FILTERED ###
0 - 6769
1 - 6792
2 - 6771
3 - 6699
4 - 6774
5 - 6595
6 - 6602
7 - 6634
8 - 6642
9 - 6640
10 - 6660
11 - 6665
12 - 6673
13 - 6772
14 - 6766
15 - 6768
16 - 6644
17 - 6635
18 - 6633
19 - 6793
20 - 6677
好吧,请注意 AllegatiPerCategorie 列表中值 6660 和 6640 的顺序:6660 在 6640(在位置 13 和 14)。
现在,在Allegati 上以相同的值顺序观看:6640 在 6660 之前(在位置 9 和 10 )。
为什么会有这种行为?我该如何解决?谢谢
【问题讨论】:
-
不,不要关闭这个!关闭另一个!请给我举个例子!!!
-
@markzzz - 你有例子吗?太好了,然后转到您的其他问题,并使用
edit链接... -
请把
AllegatiPerCategorie(联合前)的内容,Union()-argument和结果贴出来。 -
该死的你是对的!如果我先浏览 Allegati,6640 在 6660 之前...怎么可能?在存储过程上 6660 在 6640 之前...