我试图做一个单独的linq语句,以下工作但希望在一个语句中完成。
public class ClientProducts
{
public string To { get; set; }
public string ClientFullName { get; set; }
public string ClientFirstName { get; set; }
public string ProductNames{ get; set; }
}
var list =
clients.Select(
client =>
new ClientProducts()
{
To = client.TelephoneMobile,
ClientFirstName = client.FirstName,
ClientFullName = client.FullName,
//ProductNames= client.Products.Select(p=>p.Name)<-this is what I want
}).ToList();
string productName= string.Empty;
foreach (var client in clients)
{
foreach (var p in client.Products)
{
productName+= Name+ ",";
}
}
答案 0 :(得分:2)
替换
//ProductNames= client.Products.Select(p=>p.Name)
带
ProductNames = string.Join(",", client.Products.Select(p=>p.Name))