繁体   English   中英

用于存储过程的ASP.NET Web Api控制器不返回数据

[英]ASP.NET Web Api controller for stored procedure not returning data

我的数据库上有以下存储过程:

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 

然后在我的上下文类中为:

 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);
    }
}

我正在使用以下控制器访问它:

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);
        }
    }
}

现在,从理论上讲,此控制器应该返回数据,但是当通过相关的localhost / api / Historial访问时,它不返回任何数据或消息,它仅返回一个空的JSON文件。 发生了什么?

尝试这个:

    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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM