我尝试使用distinct进行分组,然后构建一个csv字符串:
[FROM]是一对多联接:
var allCustomerRoles = (from cr in Customers
join r in CustomerRoles
on cr.Role_ID equals r.Role_ID
select new { cr.Customer_No_, r.Role_ID });
所以问题是,您能否告诉我如何编写LINQ查询以达到[TO]结构,其中Customer_No_是不同的,并且它的Role_ID值被连接成CSV字符串。
答案 0 :(得分:5)
谢谢@ reda-mattar,您的链接引导我找到解决方案,这就是我要找的内容:
var allCustomerRoles = (from cr in Customers
join r in Roles
on cr.Role_ID equals r.Role_ID
group r.Role_ID by cr.Customer_No_ into g
select new { Customer_No_ = g.Key, Role_ID = string.Join(",", g.ToArray()) });