I'm quite confused since, for a many to many relationship, you need a third table.
TABLE Employee
(
EmployeeId int PRIMARY KEY IDENTITY,
EmployeeName nvarchar
)
TABLE Device
(
DevideId int PRIMARY KEY IDENTITY,
DeviceName nvarchar
)
TABLE EmployeeDevice
(
EmployeeId int FOREIGN KEY REFERENCES (Employee.EmployeeId),
DeviceId int FOREIGN KEY REFERENCES (Device.DeviceId)
)
The
EmployeeDevice
table represents the many-to-many relationship. Then, if you want all devices associated to Marco, you can write
SELECT
d.DeviceId
,d.DeviceName
FROM Device d
INNER JOIN EmployeeDevice ed on ed.DeviceId = d.DeviceId
INNER JOIN Employee e on e.EmployeeId = ed.EmployeeId
WHERE e.EmployeeName = N'Marco'
Then in Linq:
List<Device> devices = context.Devices.Where
(
d => d.DeviceEmployees.Any
(
de => de.Employee.EmployeeName.Equals("Marco")
)
);