I have a SQL Server database mapped in Entity Framework 6.
The problem is that when I query the Employee
table for an employee or for all employees, it doesn't return the Equipments
mapped with the particular employee. The Equipments
column is empty.
The results are being displayed in a DataGridView
Query Result for a Particular Employee
I queried like this:
SELECT *
FROM Employee
WHERE EmployeeID = 5;
What seems to be the problem? Can anyone help me out here?
Here are a few examples in Linq that would match your query but also include the equipment.
using (var context = new EmployeeContext()) {
var employeeData = context.Employees.Where(p=> p.EmployeeID == 5)
.Include(t => t.Equipment).FirstOrDefault();
}
or
using (var context = new EmployeeContext()) {
var employeeData = context.Employees.SqlQuery("SELECT * FROM Employee E JOIN Equipment EE ON E.EmployeeID = EE.EmployeeID WHERE E.EmployeeID = @id", new SqlParameter("@id", 5)).FirstOrDefault();
}
I would suggest reading how to pass the parameters here