【发布时间】:2020-08-12 12:43:17
【问题描述】:
我有这个存储过程:
CREATE PROCEDURE AddReserv
@Place int,
@StartDate datetime,
@EndDate datetime
AS
BEGIN
INSERT INTO [dbo].Reserv(UserId, Place, StartDate, EndDate)
VALUES (1, @Place, @StartDate, @EndDate)
END
从 post 方法中的控制器,我想向表中添加一条新记录。我不知道如何将参数传递给存储过程。
我在控制器中的代码:
// POST: api/CreateReserv
[HttpPost]
public void Post(string value)
{
using (var connection = _db.Database.GetDbConnection())
{
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText = "AddReserv";
//How to add params?
/*
@Place int
@StartDate datetime
@EndDate datetime
*/
command.ExecuteNonQuery();
}
}
}
【问题讨论】:
标签: c# asp.net-core entity-framework-core