【问题标题】:Making this query in LINQ-SQL?在 LINQ-SQL 中进行此查询?
【发布时间】:2013-01-30 00:49:20
【问题描述】:

我有Employees、Groups 和EmployeeGroupFilters。

Employee 具有带有外键关系的 GroupID。

EmployeeGroupFilter 具有员工和组 ID。每个员工都可以过滤他们不想在日历中看到的组。

因此,如果存在 EmployeeGroupFilter,则该员工将看不到该组。

我需要一个查询,该查询将返回 Group 的 IEnumerable,这将是员工可见的组。

例如:从当前员工的组过滤器中没有组的组中选择所有组。

现在我可以像这样获取所有员工过滤器:

public static IEnumerable<EmployeGroupFilter> GetAllByEmployee(
int employeeID)
{
    KezberPMDBDataContext db = new KezberPMDBDataContext();

    return from p in db.EmployeGroupFilters
           where p.EmployeID == employeeID
           select p;
}

我需要类似的东西:

public static IEnumerable<Group> GetAllVisibleEmployeeGroups(
int employeeID)
{
    KezberPMDBDataContext db = new KezberPMDBDataContext();

    return from p in db.Groups
           .......
           select p;
}

【问题讨论】:

    标签: c# asp.net sql linq


    【解决方案1】:
    return from p in db.Groups
    where !p.EmployeGroupFilters.Any(fil=>fil.EmployeeId == employeeID)
               select p;
    

    【讨论】:

      猜你喜欢
      • 2020-05-21
      • 2013-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-15
      • 1970-01-01
      相关资源
      最近更新 更多