EF Model Image References
I was planned to read data from database and then using INNER JOIN in C# WebApi contr
As per the Model given above, you should change your query as something like:
public class JoinController: ApiController
{
DepartmentServicesEntities DSE = new DepartmentServicesEntities();
[Route("Api")]
[HttpGet]
public object JoinStatement()
{
using (DSE)
{
var result = (from e in DSE.employee join d
in DSE.department on e.department_id equals d.department_id
select new {
FirstName = e.FirstName,
LastName = e.LastName,
Gender = e.Gender,
Salary = Salary,
Department_id = e.Department_id,
Department_Name = d.Department_Name
}).ToList();
// TODO utilize the above result
}
}
}
There is only one issue with the above code as the result will always be an Anonymous Type object. So, it is advisable to use a Data Transfer Object
(DTO) whenever you have a case of multi-entity join result for proper mapping.