Linq的UNION [英] UNION in Linq

查看:79
本文介绍了Linq的UNION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将以下SQL转换为LINQ:

I am trying to convert the following SQL to LINQ:

SELECT   ''Employer'' note_type, TRUNC (dated) dated, note
    FROM PHSP.employer_note
   WHERE employer = :employer AND popup = ''Y''
UNION
SELECT   ''Employee'', TRUNC (dated), note
    FROM PHSP.employee_note
   WHERE employee = :employee AND popup = ''Y''



它检查是否有针对loyer_note表的注释,然后将employee_note表中的注释连接起来.

这就是我所做的:



It checks if there is notes for the employer_note table then concatenates notes from the employee_note table.

This is what I did:

(from e in EmployerNotes
  where e.Employer == 37471 &&
  e.Popup == "Y"
  select new { Dated = e.Dated, Note = e.Note, note_type= "Employer"})
.Concat(
from n in EmployeeNotes
  where n.Employee == 34715 &&
  n.Popup == "Y"
  select new { Dated = n.Dated, Note = n.Note, note_type= "Employee"})



对于特定雇员,两个注释中都有注释,并且注释均显示在两个注释中,但是Type始终会显示"Employer",即使它应该是"Employer for first row"和"Employee" for第二行.

是否还需要其他内容,以便类型根据选择的表正确显示?

谢谢.



For the specific employee there is notes in both and the notes are shown from both, but the Type always says "Employer" even though it should be "Employer for first row and "Employee" for second row.

Is there something else needed so the types will show correctly depending on what table they were selected from?

Thank you.

推荐答案

看看这些
1) Linq-union-operator [ ^ ]
2) Linq联盟 [ 101个LINQ示例 [
Hi Have a look on these
1) Linq-union-operator[^]
2) Linq-union[^]
3) 101 LINQ Samples[^]


这篇关于Linq的UNION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆