【发布时间】:2014-01-01 16:20:11
【问题描述】:
我对相关表有一个简单(非常简单,不简单)的“不在”查询。
SELECT CompetencyID, CompetencyName FROM Competency
WHERE (Deleted = 0) AND (CompanyID = 1) AND (CompetencyID NOT IN(SELECT CompetencyID
FROM CompetencyGroups WHERE (Deleted = 0) AND (CompanyID = 1) AND (GroupID = 1))) AND
(ParentID = 0) ORDER BY CompetencyName
在 SQL 中,我得到了我需要的列表,其中包含不在组中的剩余项目。现在我想使用 EF5 将它绑定到 DataGrid。
我无法正确获取查询语法(使用 VB.net)来列出能力的 ID 和名称...
将提供的 c# 答案转换为 VB:
Dim excludeList = context.CompetencyGroups.Where(Function(x) x.Deleted = False And x.GroupID = GroupID).Select(Function(x) x.CompetencyID).ToArray
Dim results = context.Competencies.Where(Function(c) Not excludeList.Contains(c.CompetencyID) And c.Deleted = False And c.CompanyID = 1 And c.ParentID = 0).OrderBy(Function(c) c.CompetencyName)
GridView2.DataSource = results
GridView2.DataBind()
希望这对将来的某人有所帮助。我花了大约 4 个小时来搜索、询问和转换...
【问题讨论】:
标签: vb.net entity-framework-5 notin linq-query-syntax