I am very new to learning APS.NET Core Web API and I am having trouble with a result I am getting from a stored procedure I am running using FromSqlRaw
I have a class for input:
public class DevInput
{
public string DevID { get; set;}
public int Source { get; set;}
}
and I have a class for output:
public class DevOutput
{
public string Name{ get; set;}
public string Cost { get; set; }
public string OrdQty { get; set;}
public string Model { get; set}
}
I am mapping the return from a SQL stored procedure to said class with:
public class DevOutputController : ControlleBase
{
private readonly DevContext _context;
public DevOutputContoller(DevContext context)
{
_context = context
}
[HttpPost]
public async Task<ActionResult<IEnumerable<DevOutput>>> GetOutput(DevInput input)
{
string sp = "Exec DevSearch '" + input.DevID + "', " + input.Source + ""
return await _context.DevOutput.FromSqlRaw(sp).ToListAsync
}
}
This is working fine except sometimes the “Cost” returned from the stored procedure is a decimal type, and sometimes a string type depending on what sql table the “Cost” value is retrieved from
I am wondering if there is a way that I can convert whatever is returned from the stored procedure to a string so that it can properly be mapped to my output class
J. Rent is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.