【发布时间】:2021-01-04 03:38:04
【问题描述】:
我将 EF Core 和 SQL Server 本地用于我的 ASP.NET Core 后端。在 SQL Server 中,我有一个带有多个连接的长而复杂的参数化存储过程。
我这样称呼它:
[HttpGet("plantpl/{plantId}&{year}&{costAccTypeId}")]
public IActionResult GetPlantPl(long plantId, int year, long costAccTypeId)
{
SqlParameter plantIdParam = new SqlParameter("@PlantId", plantId);
SqlParameter yearParam = new SqlParameter("@Year", year);
SqlParameter costAccTypeIdParam = new SqlParameter("@CostAccTypeId", costAccTypeId);
var plantPLRows = DataContext.PlantPLRows.FromSqlRaw("PlantPl @PlantId, @Year, @CostAccTypeId",
plantIdParam, yearParam, costAccTypeIdParam);
return Json(plantPLRows);
}
为了使用FromSqlRaw方法,我必须创建一个模型类PlantPLRow和对应的DbSet PlantPLRows。
基本上,我只是想从数据库中取回一些数据并将其发送给客户端。我不想要一个新的DbSet 也不想要迁移。但是要使用FromSqlRaw,我必须使用它。
所以我的问题是:这是否适合我的情况?
【问题讨论】:
-
是的,这就是使用 EF Core 的方式
标签: asp.net-core entity-framework-core