[英]ASP.NET Web Api controller for stored procedure not returning data
I have the following stored procedure on my database: 我的数据库上有以下存储过程:
SELECT dbo.Persona.Nombre, dbo.Persona.Cedula, dbo.Prestamo.Empresa, dbo.Prestamo.Concepto, dbo.Prestamo.Monto, dbo.Prestamo.Fecha, dbo.Prestamo.PagadoATiempo
FROM dbo.Financiera INNER JOIN
dbo.Prestamo ON dbo.Financiera.RNC = dbo.Prestamo.Empresa INNER JOIN
dbo.Persona ON dbo.Prestamo.Cliente = dbo.Persona.Cedula
WHERE dbo.Persona.Cedula = @p1
which is then in my context class as: 然后在我的上下文类中为:
public partial class BDWSEntities : DbContext
{
public BDWSEntities()
: base("name=BDWSEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<Financiera> Financieras { get; set; }
public virtual DbSet<Persona> Personas { get; set; }
public virtual DbSet<Prestamo> Prestamoes { get; set; }
public virtual ObjectResult<EnviarHistorial_Result> EnviarHistorial(string p1)
{
var p1Parameter = p1 != null ?
new ObjectParameter("p1", p1) :
new ObjectParameter("p1", typeof(string));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<EnviarHistorial_Result>("EnviarHistorial", p1Parameter);
}
public virtual ObjectResult<Nullable<bool>> EnviarSalud(string p1)
{
var p1Parameter = p1 != null ?
new ObjectParameter("p1", p1) :
new ObjectParameter("p1", typeof(string));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<bool>>("EnviarSalud", p1Parameter);
}
}
and I'm using the following controller to access it: 我正在使用以下控制器访问它:
namespace Web_Services.Controllers
{
public class HistorialController : ApiController
{
private BDWSEntities db = new BDWSEntities();
public IHttpActionResult GetHistorial(string Cedula)
{
var record = db.EnviarHistorial(Cedula);
if (record == null)
{
return NotFound();
}
return Ok(record);
}
}
}
Now, in theory, this controller should return data, but when accessed via the relevant localhost/api/Historial, it doesn't return any data or message, it just returns an empty JSON file. 现在,从理论上讲,此控制器应该返回数据,但是当通过相关的localhost / api / Historial访问时,它不返回任何数据或消息,它仅返回一个空的JSON文件。 What's happening? 发生了什么?
Try this: 尝试这个:
public virtual ObjectResult<EnviarHistorial_Result> EnviarHistorial(string p1)
{
var p1Parameter = p1 != null ?
new ObjectParameter("p1", p1) :
new ObjectParameter("p1", typeof(string));
return this.Database.SqlQuery<EnviarHistorial_Result>("EnviarHistorial", p1);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.