我有两张桌子:TblAppointmentTypes
和TblEmployeeInfo
。这两个表之间存在多对多关系,连接表是TblEmployeeServices
. 中有 2 条记录, 中有TblAppointmentTypes
4 条记录TblEmployeeInfo
。的所有两条记录TblAppointmentTypes
都分配给 中的所有记录TblEmployeeInfo
,即 中有 8 条记录TblEmployeeServices
。我想检索分配给所有四个的所有服务Employees
,它应该返回分配给所有四个员工的 2,但是我的查询返回 8 条记录,四个重复的服务。
我正在使用 Telerik Open Access ORM。这是代码:
public static List<TblAppointmentType> GetAllAppointmentType(List<int> employeeIDs)
{
var list = new List<TblAppointmentType>();
if (employeeIDs != null && employeeIDs.Count > 0)
{
var dc = new Entities();
list = (from a in dc.TblAppointmentTypes.Distinct()
join e in dc.TblEmployeeServices on a.ID equals e.AppointmentTypeID
where a.IsDeleted == false && employeeIDs.Contains<int>(e.EmployeeID)
select a).ToList();
}
return list;
}