2012-07-10 120 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) }