Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用LINQ中的用例或if语句?_C#_Linq_Entity Framework - Fatal编程技术网

C# 使用LINQ中的用例或if语句?

C# 使用LINQ中的用例或if语句?,c#,linq,entity-framework,C#,Linq,Entity Framework,我有一个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 BookedAreasSe

我有一个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
    };
请导游


谢谢

您可以这样做,但是使用三元运算符

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?“第一个结果”: AreaSet.YourColumnName==YourSecond变量?“一些结果”:“一些结果” 其他结果”


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

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?“第一个结果”: AreaSet.YourColumnName==YourSecond变量?“一些结果”:“一些结果” 其他结果”


您希望IF语句做什么?是否要根据某些条件映射一列或另一列?希望IF语句执行什么操作?是否要根据某些条件映射一列或另一列?