【发布时间】:2019-12-13 17:41:05
【问题描述】:
我的查询有问题。我想在视图上显示结果。
[HttpGet]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Index()
{
return View(await _Context.Employee
.FromSql("EXEC sp_GetLoanDetails")
.ToArrayAsync());
}
这是我要查看的项目列表:
public class StoredProcRow
{
[Key]
public int empID { get; set; }
public string empFullName { get; set; }
public double EducationalLoan { get; set; }
public double PettyCash { get; set; }
public double BusinessLoan { get; set; }
public double ApplianceLoan { get; set; }
public double EmergencyLoan { get; set; }
public double AllPurposeLoan { get; set; }
public double KAPUSOIILoan { get; set; }
public double FiestaLoan { get; set; }
public double SalaryLoan { get; set; }
public double Pledge { get; set; }
public double PagIbigLoan { get; set; }
public double SSSLoan { get; set; }
public double AllAroundLoan { get; set; }
public double Total { get; set; }
}
注意:这些实体名称与sp_GetLoanDetails中列名称上的实体相同
现在可以在 EF Core 1.1 上实现吗?还是我需要返回手动 ADO.NET 代码?
谢谢!
【问题讨论】:
-
旁注:您应该不为您的存储过程使用
sp_前缀。微软有reserved that prefix for its own use (see Naming Stored Procedures),你确实会在未来某个时候冒着名称冲突的风险。 It's also bad for your stored procedure performance。最好只是简单地避免sp_并使用其他东西作为前缀 - 或者根本不使用前缀! -
@marc_s,已注明,谢谢!
标签: asp.net-core entity-framework-core