linq的查询问题
答案:1 悬赏:10
解决时间 2021-01-30 01:24
- 提问者网友:鼻尖触碰
- 2021-01-29 00:47
linq的查询问题
最佳答案
- 二级知识专家网友:大漠
- 2021-01-29 01:26
Dictionary abNames = new Dictionary();
List tempAs = new List();
// 查出所有A表记录 {ID, Name}
List tempBs = new List();
// 查出所有B表记录 {ID, A_ID, Name}
foreach (var a in tempAs)
{
var tempAB = tempBs.Where(b => b.A_ID == a.ID);
string tempABStr = string.Empty;
foreach (var ab in tempAB)
tempABStr += ab.Name + ";";
tempABStr = tempABStr.TrimEnd(';');
abNames.Add(a.Name, tempABStr);
}
// 最后使用abNames即可
List
// 查出所有A表记录 {ID, Name}
List
// 查出所有B表记录 {ID, A_ID, Name}
foreach (var a in tempAs)
{
var tempAB = tempBs.Where(b => b.A_ID == a.ID);
string tempABStr = string.Empty;
foreach (var ab in tempAB)
tempABStr += ab.Name + ";";
tempABStr = tempABStr.TrimEnd(';');
abNames.Add(a.Name, tempABStr);
}
// 最后使用abNames即可
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯