我想返回一个由SP为列的结果,这些列实际上在当前模型实体中不存在。目前,我只能返回结果,这是目前的模式之一。
[HttpGet]
public async Task<ActionResult> getAllSalaryRanks()
{
HttpResponseMessage response = new HttpResponseMessage();
using(db963Context context = new db963Context())
{
var ranks = context.IoVouchersSalaryRanks.FromSqlRaw("EXEC ioVouchers_sp_SalaryRanks").ToList();
return Ok(ranks);
}
}
在上面的例子中,我将得到一个异常:The required column 'foo' was not present in the results of a 'FromSql' operation.
基本上,IoVouchersSalaryRanks
是我的模型之一,所以结果的列应该与模型实体一样精确。如何添加自定义模型实体,以便SP将返回与该自定义模型的结果匹配?
发布于 2020-04-16 15:07:00
这意味着存储过程不返回列foo
。试着:
Foo
添加到SELECT
语句Foo
列使用[NotMapped]
。此属性可用于不希望在数据库中为其创建相应列的实体类的属性。
https://stackoverflow.com/questions/61253446
复制相似问题