Reputation: 1055
I have written a method in Repository class for which I have created a Controller in Web API project. Following is my Model class:
namespace Meijer.Merch.Space.Data
{
public class FloorplanAnalyst
{
public int EmpId { get; set; }
public string EmpName { get; set; }
}
}
Following is the method in Repository class:
public IEnumerable<FloorplanAnalyst> GetFloorplanAnalyst()
{
return this.Database.SqlQuery<FloorplanAnalyst>("GET_FLOORPLAN_ANALYSTS").ToList();
}
Following is my Controller method:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace SpaceWebApi.Controllers
{
/// <summary>
/// Controller used for the retrieving of FloorplanAnalyst information
/// </summary>
public class FloorplanAnalystController : ApiController
{
private ISpaceRepository db = new SpaceRepository();
/// <summary>
/// Returns a list of FloorplanAnalysts.
public IEnumerable<FloorplanAnalyst> GetFloorplanAnalyst()
{
return db.GetFloorplanAnalyst();
}
}
}
But I am getting following records as my result (27 rows are returned):
{
"EmpId": 0,
"EmpName": null
},
{
"EmpId": 0,
"EmpName": null
}
}
In SQL Server correct data is returned when the stored procedure is executed. But at Web API end it is not correct.
Upvotes: 2
Views: 1007
Reputation: 23200
You have this issue because EmpId
and EmpName
properties into FloorplanAnalyst
class don't match the columns name returned by your GET_FLOORPLAN_ANALYSTS
stored procedure.
To solve this, make sure that each property have an associated column name (same name as the property) in the result query from your stored procedure.
Upvotes: 1