簡體   English   中英

加入C#以獲得兩個條件

[英]joining in C# for two condtions

我必須在兩個表Price和Operator之間進行條件連接

表價格

  1. 顧客姓名
  2. 單價
  3. 國家

表操作員

  1. OpertorName
  2. 國家

加入需要在以下兩個條件下運行:

一個。 如果表格中的記錄的代碼為空,則僅基於國家/地區加入(所有選定國家/地區的代碼將包含在表格運算符中)

如果表格中的記錄存在代碼,則根據國家和代碼加入

請幫忙

//If Code is null in table Price for a record then :

 var reportList = (from pl in Prices
                          join ml in Operators 
                          on pl.Country equals ml.Country                          
                          select new PriceReports {  }

//If Code is present in table Price for a record then 

    var reportList = (from pl in Prices
                          join ml in Operators 
                          on new { a = pl.Country, b = pl.MNC } equals new { a = ml.Country, b = ml.Code }
                          select new PriceReports {  }

我想創建一個單獨的查詢來表示上述兩種情況

你不能用LinQ中使用的連接語法編寫這樣的連接,你需要在where條件下使用交叉連接。

var reportList = from pl in PriceS
                 from ml in Operators.Where(mList => mList.Country == pl.Country
                                                   && (pl.Code == null || mList.Code == pl.Code))
                 select new PriceReports {  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM