C# 在LINQ联接中添加自定义值

C# 在LINQ联接中添加自定义值,c#,linq,C#,Linq,我有两份清单: FXCashFlow[包含-金额、付款日期、交易ID、货币] FXTrades[包含-TradePreferences,TradeId] 在返回类中,我需要的是: 返回对象[类型、金额、付款日期、贸易ID、货币、贸易优惠] 其中Type=“Fx”,因为数据是从Fx类获取的 对于返回对象,我使用LINQ连接,如下所示: var list = _fxCashflow.GetAll().Join(_fxTrade.GetAll(), outerKey

我有两份清单:

  • FXCashFlow[包含-金额、付款日期、交易ID、货币]
  • FXTrades[包含-TradePreferences,TradeId]
在返回类中,我需要的是:

  • 返回对象[类型、金额、付款日期、贸易ID、货币、贸易优惠]
其中Type=“Fx”,因为数据是从Fx类获取的

对于返回对象,我使用LINQ连接,如下所示:

 var list = _fxCashflow.GetAll().Join(_fxTrade.GetAll(),
             outerKey => outerKey.TradeId,
             innerKey => innerKey.TradeId,
             (CashFlow, Trade) => new
             {
                //"Fx", <- This line gives error
                CashFlow.TradeId,
                Trade.TradeReference,
                CashFlow.PaymentAmount,
                CashFlow.CurrencyCode,
                CashFlow.PaymentDate,
                CashFlow.CashflowTypeCode
             }
            );
var list=\u fxCashflow.GetAll().Join(\u fxTrade.GetAll(),
outerKey=>outerKey.TradeId,
innerKey=>innerKey.TradeId,
(现金流、交易)=>新
{

//“Fx”,试着像这样插入它:

         (CashFlow, Trade) => new
         {
            Type = "Fx",
            CashFlow.TradeId,
            Trade.TradeReference,
            CashFlow.PaymentAmount,
            CashFlow.CurrencyCode,
            CashFlow.PaymentDate,
            CashFlow.CashflowTypeCode
         }

您可以将此信息存储在enum中并在匿名对象中使用,也可以为匿名对象定义新属性。

引入实际的
Fx
类而不是使用字符串标识符是否更有意义

public class Fx
{
    public int TradeId { get; set; }
    public string TradeRef { get; set; }
    public decimal PaymentAmount { get; set; }
    ...
}

(CashFlow, Trade) => new Fx
{
    TradeId = CashFlow.TradeId,
    TradeRef = Trade.TradeReference,
    PaymentAmount = CashFlow.PaymentAmount,
    ...
}