【发布时间】:2021-09-16 22:35:18
【问题描述】:
我在 SQL Server 2012 和 Web API 实体框架 .NET core 2.2 上工作 所以我面临的问题是我无法在下面实现 Web API 执行存储过程
Create proc ItemCalculateStock
@ItemId int = NULL,
@InventoryLocation int=NULL
as
begin
SELECT i.itemName,l.InventoryName, SUM(case when QTY > 0 then QTY else 0 end) as PurchasedItem,SUM(case when QTY < 0 then -QTY else 0 end) as ConsumItems,SUM(case when QTY > 0 then QTY else 0 end) + SUM(case when QTY < 0 then QTY else 0 end) as remaining
FROM [dbo].[Invenroty] n with(nolock)
inner join [dbo].[InventoryLocations] l with(nolock) on l.id=n.InventoryLocID
inner join [dbo].[Items] i with(nolock) on n.itemid=i.id
inner join [dbo].[TransactionTypes] t with(nolock) on n.transactionTypeId=t.ID and InventoryLocID=case when @InventoryLocation is null then n.InventoryLocID else @InventoryLocation end
and i.id=case when @ItemId is null then n.itemid else @ItemId end
GROUP BY i.itemName,l.InventoryName
end
so 如何使用 Entity Framework .NET core 2.2 在 Web API 上获取存储过程的结果
[HttpGet("CalculateInventoryData")]
public IActionResult CalculateInventoryData([FromQuery]int optionId, [FromQuery] int ItemId, [FromQuery] int InventoryLocation)
{
// here how to get stored procedure result here
// so i ask question to know how to get result of stored procedure above
}
要调用 API,我使用以下链接:
https://localhost:44374/api/Inventory/getInventoryData?optionId=1&ItemId=2&InventoryLocation=1
更新帖子
我在下面试试
context.Database.ExecuteSqlCommand("ItemCalculateStock @OptionId ,@ItemId,@InventoryLocation ", parameters: new[] {optionId,ItemId,InventoryLocation});
i get error cannot implicitly convert type int into to Microsoft .aspnetcore.mvc.action result
so how to solve issue
【问题讨论】:
标签: asp.net-mvc-4 asp.net-web-api asp.net-core-webapi asp.net-core-2.1 c#-7.0