【问题标题】:How to call stored procedure in EF code-first approach?如何在 EF 代码优先方法中调用存储过程?
【发布时间】:2017-04-27 04:36:44
【问题描述】:

我正在使用具有代码优先方法的实体框架。你能提供一些关于如何从我的代码中调用存储过程的建议吗?

存储过程:

create procedure sp_GetCountry
As
Begin
    select * 
    from Country
End

Homectrol.cs:

 JanContext db = new JanContext ()

 public JsonResult GetCountry_sp()
 {
     string storedprocedure = "sp_GetCountry";
 }

【问题讨论】:

标签: c# ef-code-first


【解决方案1】:

尝试使用EntityFramework Reverse POCO生成器

编辑.tt文件如下

 IncludeStoredProcedures = false;

 IncludeStoredProcedures = true;

这将在 DbContext 中创建名为 storedprocedure 的函数,您需要调用此函数这将调用存储过程

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多