如何在codefirst方法实体框架中调用存储过程 [英] How to call stored procedure in codefirst approach entity framework

查看:117
本文介绍了如何在codefirst方法实体框架中调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何调用存储过程,所以有人可以帮助我.....



我尝试了什么:



公共类DemoEntityContext:DbContext

{

public DemoEntityContext():base(DbContext ){}

public DbSet< student>学生{得到;组; }

public DbSet< course>课程{get;组; }

public DbSet< enrollment>报名{get;组; }



protected override void OnModelCreating(DbModelBuilder modelBuilder)

{

modelBuilder.Entity< student>() .MapToStoredProcedures();

}



公共学生GetDetailsByID(字符串详细信息)

{

//在这个函数中我需要调用SP;

}

}

I don't know how to call a stored procedure so someone can help me out.....

What I have tried:

public class DemoEntityContext : DbContext
{
public DemoEntityContext() : base("DbContext") { }
public DbSet<student> Students { get; set; }
public DbSet<course> Courses { get; set; }
public DbSet<enrollment> Enrollments { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<student>().MapToStoredProcedures();
}

public Student GetDetailsByID(string Details)
{
// in this function i need to call the "SP";
}
}

推荐答案

Google提供多种解决方案。比如这个 - c# - 如何在实体框架6(代码优先)中调用存储过程? - 堆栈溢出 [ ^ ]
There are several solutions available via Google. Such as this one - c# - How to call Stored Procedure in Entity Framework 6 (Code-First)? - Stack Overflow[^]


这篇关于如何在codefirst方法实体框架中调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆