2012-07-10 118 views
0

我有一個LINQ查詢(使用EF)在LINQ選擇結果中添加一個計算的字段?

基本上我想添加一列中的選擇結果基於另一列的值。

我在DB表中有PaymentDate列,但沒有Paid列。如果PaymentDate列中有空,它也顯示付款是虛假的,如果它有某個日期,則意味着付款是真實的。

這是我的查詢,請指導我如何做到這一點。

var selectedResults= 
    from InvoiceSet in Invoices 
    join BookedAreasSet in BookedAreas 
    on InvoiceSet.InvoiceID equals BookedAreasSet.InvoiceID 
    join AreaSet in Areas on BookedAreasSet.AreaID equals AreaSet.AreaID 
    select new  {InvoiceSet.InvoiceNumber,InvoiceSet.Amount,InvoiceSet.TotalDiscount,InvoiceSet.GST,  InvoiceSet.PaymentDate,InvoiceSet.ShoppingCentreID,BookedAreasSet.BookedAreaID, 
AreaSet.Name,Here I want to add calculated value column based on InvoiceSet.PaymentDate value} 

回答

2

我想你應該能夠做這樣的事

var selectedResults= 
    from InvoiceSet in Invoices 
    join BookedAreasSet in BookedAreas 
    on InvoiceSet.InvoiceID equals BookedAreasSet.InvoiceID 
    join AreaSet in Areas on BookedAreasSet.AreaID equals AreaSet.AreaID 
    select new { InvoiceSet.InvoiceNumber,InvoiceSet.Amount,InvoiceSet.TotalDiscount,InvoiceSet.GST,  
     InvoiceSet.PaymentDate,InvoiceSet.ShoppingCentreID,BookedAreasSet.BookedAreaID, 
     AreaSet.Name,Paid = (InvoiceSet.PaymentDate == null) }