[英]LINQ query(Lambda Expressions) and String.Join
如何為這種類型的 LINQ 查詢(Lambda 表達式)編寫 Strng.Join? (var b 將返回 integer 列表的數量)
1.
var b = braughtForwardInvoices
.Where(x => x.LinkedTransaction != null
&& x.LinkedTransaction.Count > 0)
.Select(x => x.LinkedTransaction.Select(x => x.TransactionId))
.ToList();
下面顯示了實際的工作查詢。 我需要像數字 2 一樣在數字 1 中編寫代碼。
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();
獲取列表並將其發送到 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);
如果您只需要選定的 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.