首页 > 解决方案 > 邮递员发布请求响应带有空参数

问题描述

我正在尝试通过使用 Service 类中的 ExecuteSqLRaw() 来执行将值插入表的存储过程。


public Category AddCategory(Category category)
     {

         db.Database.ExecuteSqlRaw("[dbo].[CatinsertSP] {0},{1},{2},{3},{4},{5},{6},{7}", category.CategoryId, category.CategoryCode, category.CategoryName, category.AboutCategory, category.ParentCategoryId, category.IsEnable, category.IsActive, category.IsBlock);
         return category;
     }

这是 Postman { "Category_Code":"130", "Category_Name":"Kids" } 中的请求正文

这是状态为 200 { "categoryId": "00000000-0000-0000-0000-000000000000", "categoryCode": null, "categoryName": null, "aboutCategory": null, "parentCategoryId": null, "isEnable “:空,“isActive”:空,“isBlock”:空,“updateLog”:空,“createdOn”:空,“createdBy”:空,“updateOn”:空,“updateBy”:空,“seqNo”: 0, "module": [], "product": [] } 这是存储过程

ALTER PROCEDURE [dbo].[CatinsertSP] 
    -- Add the parameters for the stored procedure here
    @Category_Id uniqueidentifier ,
    @Category_Code nvarchar(20),
    @Category_Name nvarchar(167),
    @About_Category nvarchar(max),
    @Parent_Category_Id uniqueidentifier,
    @Is_Enable bit,
    @Is_Active bit,
    @Is_Block bit
    
    
    
AS
BEGIN

    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    
    

    -- Insert statements for procedure here
    insert into [dbo].[Category] (Category_Id,Category_Code,Category_Name,About_Category,Parent_Category_Id,Is_Enable,Is_Active,Is_Block) values(newid(),@Category_Code,@Category_Name,@About_Category,@Parent_Category_Id,@Is_Enable,@Is_Active,@Is_Block)
    select * from Category where Category_Id=@Category_Id
     


END
Go

这是控制器代码`

[HttpPost]
        public ActionResult<Category> AddCategory([FromBody]Category category)
        {
            return _service.AddCategory(category);
        }

我不明白问题出在邮递员还是在调用存储过程?我是新手,请帮忙。

标签: asp.netstored-proceduresasp.net-core-3.1webapi

解决方案


推荐阅读