0

我有一个 LINQ 查询(与 EF 一起使用)

我有以下 LINQ 查询。请指导我如何在此查询中使用 case 或 if 语句。

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 use Case/ If statment based on some other column
    };

请指导。

谢谢

4

1 回答 1

5

你可以这样做,但使用三元运算符?

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, YourColumn = AreaSet.YourColumnName == yourVariable ? "firstResult" : "other result?"}

您可以通过这种方式组合多个条件。

AreaSet.YourColumnName == yourVariable ? “firstResult”:AreaSet.YourColumnName == YoursecondVariable?“一些结果”:“一些其他结果”

于 2012-07-10T07:01:30.160 回答