I have two tables: TblAppointmentTypes
and TblEmployeeInfo
. There is many to many relation between these two tables with a joined table that is TblEmployeeServices
. There are two records in TblAppointmentTypes
and four records in TblEmployeeInfo
. All the two records of TblAppointmentTypes
is assigned to all of the records in TblEmployeeInfo
, that there is eight records in TblEmployeeServices
. I want to retrive all the services that are assigned to all the four Employees
, it should return 2 that is assigned to all the four employees, but my query return 8 records, four duplicate services.
I am using Telerik Open Access ORM. Here is the code:
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;
}