如何在不使用join-on-equals-into子句的情况下在C#LINQ中对对象执行左外连接?有没有办法用where条款做到这一点?正确的问题:对于内连接很容易,我有这样的解决方案
List<JoinPair> innerFinal = (from l in lefts from r in rights where l.Key == r.Key
select new JoinPair { LeftId = l.Id, RightId = r.Id})
Run Code Online (Sandbox Code Playgroud)
但对于左外连接我需要一个解决方案.我是这样的,但它不起作用
List< JoinPair> leftFinal = (from l in lefts from r in rights
select new JoinPair {
LeftId = l.Id,
RightId = ((l.Key==r.Key) ? r.Id : 0
})
Run Code Online (Sandbox Code Playgroud)
JoinPair是一个类:
public class JoinPair { long leftId; long rightId; }
Run Code Online (Sandbox Code Playgroud) 我是LINQ的新手,但我想知道是否可以使用LINQ从以下布局转移数据:
CustID | OrderDate | Qty
1 | 1/1/2008 | 100
2 | 1/2/2008 | 200
1 | 2/2/2008 | 350
2 | 2/28/2008 | 221
1 | 3/12/2008 | 250
2 | 3/15/2008 | 2150
Run Code Online (Sandbox Code Playgroud)
进入这样的事情:
CustID | Jan- 2008 | Feb- 2008 | Mar - 2008 |
1 | 100 | 350 | 250
2 | 200 | 221 | 2150
Run Code Online (Sandbox Code Playgroud) 可能重复:
是否可以使用LINQ旋转数据?
我想知道是否可以用Linq创建交叉表样式结果.我有一些看起来如下的数据:
var list = new[]
{
new {GroupId = 1, Country = "UK", Value = 10},
new {GroupId = 1, Country = "FR", Value = 12},
new {GroupId = 1, Country = "US", Value = 18},
new {GroupId = 2, Country = "UK", Value = 54},
new {GroupId = 2, Country = "FR", Value = 55},
new {GroupId = 2, Country = "UK", Value = 56}
};
Run Code Online (Sandbox Code Playgroud)
而我正在尝试输出到转发器控件,如下所示:
GroupId.....UK.....FR.....US
1...........10.....12.....18
2...........54.....55.....56
Run Code Online (Sandbox Code Playgroud)
它的动态列导致了我的问题.对此有何解决方案?