Hello all,
Firstly, this question is about WebAPI. But as i didnt found WebAPI under Category Dropdown, i posted under .NET General.
I'm working on MVC WebAPI, where WebAPI Performs a GET operation. But i'm unable to return type of IHttpActionResult.
Below is my WebAPI GET Action method.
- public IHttpActionResult GetDataFromDB()
- {
- try
- {
- using (var ctx = new AdventureWorks2012Entities())
- {
- var query = (from d in ctx.Departments
- join h in ctx.EmployeeDepartmentHistories
- on d.DepartmentID equals h.DepartmentID
- join s in ctx.Shifts on h.ShiftID equals s.ShiftID
- join e in ctx.Employees
- on h.BusinessEntityID equals e.BusinessEntityID
- join p in ctx.People
- on h.BusinessEntityID equals p.BusinessEntityID
- select new
- {
- Name = ((p.FirstName == null ? "" : p.FirstName) + " " +
- (p.MiddleName == null ? "" : p.MiddleName) + " " +
- (p.LastName == null ? "" : p.LastName)), MaritalStatus = (e.MaritalStatus == "M" ? "Married" : "Single"),
- Gender = (e.Gender == "M" ? "Male" : "FeMale"),
- Designation = e.JobTitle,
- Department = d.Name,
- MajorBranch = d.GroupName
- }).ToList();
- if (query.Count == 0)
- {
- return NotFound();
- }
- return Ok(query);
- }
- }
- catch (Exception) { return null; }
- finally
- {
-
- }
- }
Above code is working fine when i debug & Line # 29 show data in List format. But on browser it displaying as Error.
I can view output on Fiddler.
Please suggest me to figure out my mistake & achieve this.
Thanks in advance.