向linq查询结果添加新记录

时间:2014-01-20 20:11:09

标签: c# linq

我的查询如下:

var paymentInfo = 
    from i in dbconnect.tblPayments
    where i.tenderId == _tenderId
    select i;

此查询有一些结果,但我需要从变量PaymentInfo中添加我已有的其他结果。

例如假设我的查询有2个结果我需要将另一个结果添加到" PaymentInfo"使用linq。

我认为结果是一种列表,我可以调用.Add(PaymentInfo),但这不起作用

我该怎么做?

2 个答案:

答案 0 :(得分:2)

您可以使用Concat将另一个序列连接到此序列的末尾。

var paymentInfo = paymentInfo.Concat(someOtherPayments);

答案 1 :(得分:1)

  

我认为结果是一种列表

不,结果是IEnumerable<T>是只读的。您可以通过调用.ToList()然后添加项目来创建列表。

var paymentInfo = (from i in dbconnect.tblPayments 
                  where i.tenderId == _tenderId 
                  select i).ToList();

paymentInfo.Add(existingPayment);
相关问题