[英]LINQ query(Lambda Expressions) and String.Join
How to write a Strng.Join for this type of LINQ query(Lambda expression)?如何为这种类型的 LINQ 查询(Lambda 表达式)编写 Strng.Join? (var b will return number of integer lists)
(var b 将返回 integer 列表的数量)
1. 1.
var b = braughtForwardInvoices
.Where(x => x.LinkedTransaction != null
&& x.LinkedTransaction.Count > 0)
.Select(x => x.LinkedTransaction.Select(x => x.TransactionId))
.ToList();
Below show the actual working query.下面显示了实际的工作查询。 I need to write the code in number 1 like number 2.
我需要像数字 2 一样在数字 1 中编写代码。
2. 2.
var braughtForwardPaymentId =
from item in braughtForwardInvoices
where item.LinkedTransaction != null
&& item.LinkedTransaction.Count > 0
select string.Join(",", item.LinkedTransaction.Select(x => x.TransactionId)).ToString();
Take the list and send it to string.Join.获取列表并将其发送到 string.Join。
var b = braughtForwardInvoices.Where(x => x.LinkedTransaction != null
&& x.LinkedTransaction.Count > 0)
.Select(x => x.LinkedTransaction.Select(x => x.TransactionId))
.ToList();
var result = string.Join(",", b);
If you just need the selected IDs as a CSV string, you can join the resulting IEnumerable
:如果您只需要选定的 ID 作为 CSV 字符串,则可以加入生成的
IEnumerable
:
var b = string.Join(", ", braughtForwardInvoices.Where(x => x.LinkedTransaction != null
&& x.LinkedTransaction.Count > 0)
.Select(x => x.LinkedTransaction.Select(x => x.TransactionId)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.