我有一个实体如下
public class A
{
public string TestMethodName { get; set; }
public string FailedFor { get; set; }
}
我正在填充,然后执行联合
List<A> aCollection = new List<A>();
List<A> bCollection = new List<A>();
aCollection.Add(new A { TestMethodName = "Method1", FailedFor = "DPLServerURL" });
aCollection.Add(new A { TestMethodName = "Method2", FailedFor = "DPLServerURL" });
aCollection.Add(new A { TestMethodName = "Method3", FailedFor = "DPLServerURL" });
aCollection.Add(new A { TestMethodName = "Method4", FailedFor = "DPLServerURL" });
bCollection.Add(new A { TestMethodName = "Method1", FailedFor = "OrderXmlLocation" });
bCollection.Add(new A { TestMethodName = "Method2", FailedFor = "OrderXmlLocation" });
bCollection.Add(new A { TestMethodName = "Method5", FailedFor = "OrderXmlLocation" });
var kk = aCollection.Union(bCollection);
我正在寻找的是 TestMethodNames 和 FailedFor 上的 group by 应该用逗号分隔。
例如最终输出应该是
Method1 DPLServerUrl,OrderXmlLocation
Method2 DPLServerUrl,OrderXmlLocation
Method3 DPLServerUrl
Method4 DPLServerUrl
Method5 OrderXmlLocation
我的尝试
var mm = kk.GroupBy(g => g.TestMethodName)
.Select(group =>
new
{
Name = group.Key,
AggregateFailedFor= group.Aggregate("",(a, b) => a.Join(",",b.FailedFor))
});
我收到编译时错误
成员 'string.Join(string, params string[])' 不能通过实例引用访问;改为使用类型名称来限定它
请帮忙
谢谢