好的,我一直对我的头撞了几天,在学习LINQ之后,我想我正走在正确的轨道上。但我有一个SQL大脑,有时很难转化为C#。LINQ加入和orderby问题
我有两个数组,一个按字母顺序排序,另一个按ID排序。我需要按字母顺序排列第二个数组。 ID是连接因素。 I.E. A.ID = P.ID.
这里是我的数组和示例值;
private IGenericListItem[] _priceLevels = new IGenericListItem[0];
_priceLevels is in the form of {ID, Name}
{3, A}
{8, B}
{4, C}
{7, D}
{5, E}
{9, F}
{1, G}
编辑:更新这表明_assignmentControls包含一个子阵列。我没有让这个疯狂的理由变成这样。它实际上包含_priceLevels的副本...问题的
protected ArrayList _assignmentControls = new ArrayList();
_assignmentControls is in the form of {ID, LastPrice, NewPrice, _priceLevels[]}
{1, 1.00, 2.00, _priceLevels}
{2, 1.00, 2.00, _priceLevels}
{3, 1.00, 2.00, _priceLevels}
{4, 1.00, 2.00, _priceLevels}
部分作为我试图比较/加入一个ArrayList和IGenericListItem。
In SQL I would do something like this;
SELECT A.*
FROM _assignmentControls A JOIN _priceLevels P
ON A.ID = P.ID
ORDER BY P.Name
这将返回我在_priceLevels值进行排序的_assignmentControls表。
在C#LINQ我得到了这么多,但似乎无法得到正确的;
var sortedList =
from a in _assignmentControls
join p in _priceLevels on a equals p.ID
orderby p.Name
select _assignmentControls;
我在加入和orderby下得到红色的小方块,p.Name中的p是红色的。 和A)它不起作用。 B)我不确定它将返回sortedList作为按_priceLevels.Name排序的_assignmentControls的排序版本。编辑:当我把鼠标悬停在“加入”时,我得到了“IEnumerable System.Linq.Enumerable.Join(这个Enumerable,IEnumerable,Func,Func ....”方法的类型参数不能从。!查询我研究,现在
感谢您寻找
将联接中的'a'更改为'a.ID'。 –
@newStackExchangeInstance - 我改为:在a.ID上的_priceLevels中加入p等于p.ID,现在a.ID中的a也是红色。这让我感到困惑,因为我应该能够引用ArrayList的那个字段。 – BClaydon
我认为你需要在末尾选择 –