[英]joining in C# for two condtions
我必須在兩個表Price和Operator之間進行條件連接
加入需要在以下兩個條件下運行:
一個。 如果表格中的記錄的代碼為空,則僅基於國家/地區加入(所有選定國家/地區的代碼將包含在表格運算符中)
灣 如果表格中的記錄存在代碼,則根據國家和代碼加入
請幫忙
//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.