2

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.

2
  • Is GET_FLOORPLAN_ANALYSTS as stored procedure ? Commented Feb 10, 2016 at 6:55
  • yes it is a stored procedure Commented Feb 10, 2016 at 6:58

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I cannot change my stored procedure column names but I need EmpID and EmpName at front end. How do I make it possible?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.