簡體   English   中英

Linq用Where子句左連接

[英]Linq Left Join with Where clause

我有我正在使用MySql的實體框架5執行此查詢。

var employeeDetails = (from em in entities.employeemasters.AsEnumerable()
                       join sf in entities.salaryfitments.AsEnumerable()
                       on em.empID equals sf.empID into emsf
                       from x in emsf
                       where (x.edCode.ToString().Trim().Equals(txtEDCode.Text)
                       && x.edCode != "SYS001")
                       select new { em, x });  

where (x.edCode.ToString().Trim().Equals(txtEDCode.Text)檢查是否為該員工存儲了任何收入/扣除額,如果可以,我可以得到金額數字。

我希望查詢返回所有雇員,如果他們沒有與txtEDCode.Text匹配的特定收入/扣除額,則返回默認值。

我無法將.DefaultIfEmpty() where (x.edCode.ToString().Trim().Equals(txtEDCode.Text)

我應該怎么做才能得到合適的結果?

例如,不是返回整個實體,而是創建一個僅包含我感興趣的字段的新對象,並使用三元數(如果要在select語句中提供默認值)。

select new { 
    name = x.Name, 
    salary = x.Salary, 
    code = string.IsNullOrEmpty(x) ? "Blah" : x 
}

暫無
暫無

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

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