如何在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[^]