尝试在vb中使用linq将两个数据集连接在一起。 我的第一个数据集包含所有帐户的列表,而我的第二个数据集包含所有具有余额的帐户。 我想做一个连接,让我获得所有帐户,包括有余额的帐户。
这是我的代码
Dim results = From a In accounts
Group Join ba In balanceAccounts On c.AccountId Equals a.AccountId Into Group
From p In Group.DefaultIfEmpty()
Select New With {.Name = a.Name, .Balance = ba.Balance
}
答案 0 :(得分:0)
没有加入:
balanceAccounts
.Select(x => new Result() { Name = x.Name, Balance = x.Balance })
.Union(accounts.Select(x => new Result() { Name = x.Name, Balance = x.Balance }))
.GroupBy(x => x.Name)
.Select(x => x.First())
.ToList();
抱歉c#; - )
答案 1 :(得分:0)
在您的代码中,更改此
From p In Group.DefaultIfEmpty()
到
From ba In Group.DefaultIfEmpty()
或.Balance = ba.Balance
至.Balance = p.Balance
答案 2 :(得分:0)
Dim results = From a In accounts
Group Join ba In balanceAccounts On c.AccountId Equals a.AccountId Into Group
From ba In Group.DefaultIfEmpty()
Select New With
{ .Name = a.Name, .Balance = ba.Balance }
HF