I have this stored procedure
in sql-server
.
CREATE PROCEDURE current_call
-- Add the parameters for the stored procedure here
@call_id int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT dbo.Call.call_id, dbo.Call.city, dbo.Call.call_received, dbo.Call.call_transfer, dbo.Call.call_response, dbo.Call.call_depart, dbo.Call.call_arrive, dbo.Call.call_return, dbo.Call.call_end, dbo.Priority.name AS priorityName, dbo.Call_Status.name as Call_Status,
dbo.Station.station_name, dbo.City.city_name, dbo.Protocol.name AS protocolName
FROM dbo.City INNER JOIN
dbo.Call INNER JOIN
dbo.Priority ON dbo.Call.priority = dbo.Priority.priority_id ON dbo.City.city_id = dbo.Call.city INNER JOIN
dbo.Protocol ON dbo.Call.protocol_category = dbo.Protocol.id LEFT OUTER JOIN
dbo.Station INNER JOIN
dbo.Ambulance ON dbo.Station.station_id = dbo.Ambulance.ambulance_station ON dbo.Call.amb_id = dbo.Ambulance.ambulance_id
INNER JOIN
dbo.Call_Status ON dbo.Call.call_status = dbo.Call_Status.call_status_id
WHERE dbo.Call.call_id=@call_id;
END
GO
I'm trying to call it through a controller and print the retrieved fields as a json
string with no luck!
这是我的控制器:
public System.Web.Http.Results.JsonResult<String> GetTwo(int c_id)
{
using (EMSMVCEntities entities = new EMSMVCEntities())
{
entities.Configuration.ProxyCreationEnabled = false;
var query = entities.Database.SqlQuery<ObjectResult>("exec [dbo].[current_call] @call_id", new SqlParameter("call_id", c_id)).ToList();
return Json (query.ToString());
}
}
但是,出现以下错误:
System.InvalidOperationException:'结果类型 'System.Data.Entity.Core.Objects.ObjectResult'可能不是抽象的, 必须包含默认构造函数。”
I also tried the following code and the result was "-1"
var query = entities.Database.ExecuteSqlCommand("exec [dbo].[current_call] @call_id", new SqlParameter("call_id", c_id)).toString();