0

I have Employees, Groups, and EmployeeGroupFilters.

An Employee has a GroupID with foreign key relationship.

An EmployeeGroupFilter has an Employee and Group ID. Each employee can filter which groups they do not want to see in the calendar.

Thus, if an EmployeeGroupFilter exists, that employee will not see that group.

I need a query that will return an IEnumerable of Group which will be the groups that are VISIBLE to the employee.

Ex: select all from Groups where group not in currentEmployee's Group filters.

Right now I can get all the employees filters like this:

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

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

I need something like:

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

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

1 Answer 1

3
return from p in db.Groups
where !p.EmployeGroupFilters.Any(fil=>fil.EmployeeId == employeeID)
           select p;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.