【发布时间】:2012-02-09 19:27:36
【问题描述】:
这是我一直试图解决的情况
让我们来一张 Employee 表
Create Table Employee
(
Employeeid int primary key,
EMPname varchar(50),
ManagerEmplId int reference key Employee (EmployeeID)
TreeLevel int,
....
)
这里我需要找到所有叶级员工。
叶级员工 - 拥有经理但没有任何人向他们汇报的所有员工。我从具有 TreeLevel 列的 db 获得了一点帮助,我可以在其中指定选择级别 3 的任何人,但我需要一个 UNIONclause 它将让我获得树级别 2 的所有员工,而这些员工没有任何员工报告。 如果这有助于创建 linq 查询,我只有 3 级树。
return ((from b in _db.Employees
&& b.TreeLevel==3 && b.DeletedDate== null
select b)
.Union
(from b in _db.Employees
select b)
)
.ToDictionary(k => k.EmployeeID, v => v.EMPname);
更新: 真正的查询:
(from fi in firm
join bra in _db.Branches on fi.BranchID equals bra.ParentBranchID into g
from sc in g.DefaultIfEmpty()
where fi.DeletedDate == null && g == null
select fi)
.ToList()
.ToDictionary(k => k.BranchID, v => v.BranchName);
错误:
Cannot compare elements of type 'System.Collections.Generic.IEnumerable`1'.
Only primitive types (such as Int32, String, and Guid) and entity types are supported.
【问题讨论】:
标签: c# linq-to-sql join union