Search code examples
asp.netentity-frameworklinq-to-entities

must declare the scalar variable "@nInstID"


I am using a ADO.NET Entity Data Model for accessing my tables and stored procedure. I mapped stored procedure to my Room table as it returning sfloor column. In Entity Framework, my get request method for floor is:

public List<Floor> GetFloorList(long instID,long userID,string userRole, long buildID, long deptID)
{
    try
    {
        var floors = dbdata.Database.SqlQuery<Room>("GetUserFloorList @nInstID, @nUserID, @sUserRole, @nBuildID, @nDeptID", instID, userID, userRole, buildID, deptID);

        List<Floor> floorList = new List<Floor>();

       foreach (var fl in floors)
        {
            Floor floor = new Floor();
            floor.floorName = fl.sFloor;
            floorList.Add(floor);
        }

        return floorList;
    }
    catch(Exception)
    {
        throw;
    }
}

As I want to list out all the floor name which belongs to corresponding parameters. But when I am running this method it giving me above error.

As per some solution I need to mention data types of each variable but I am not sure how to do that. Can anyone tell me what to do?

Thanks in advance.


Solution

  • Instead of passing parameters with your variable directly, you have to use new SqlParameter("@nInstID", instID) and do this for all your parameters.