Verwenden einer gespeicherten Prozedur im Entitätsframework
Ich benutze asp.net mvc 5 und C # mit Entity Framework ... Ich habe Modell- und Domänenklassen für die Funktion ... jetzt muss ich gespeicherte Prozeduren verwenden ... die ich bei der Bewegung zu kämpfen habe.
Ich folge dem Code zuerst einer vorhandenen Datenbank und habe dort eine gespeicherte Prozedur geschrieben. Meine Frage ist, wie ich diese gespeicherte Prozedur in meiner Webanwendung aufrufen kann.
Gespeicherte Prozedur:
ALTER PROCEDURE [dbo].[GetFunctionByID](
@FunctionId INT
)
AS
BEGIN
SELECT *
FROM Functions As Fun
WHERE Function_ID = @FunctionId
END
Domänenklasse:
public class Functions
{
public Functions()
{
}
public int Function_ID { get; set; }
public string Title { get; set; }
public int Hierarchy_level { get; set; }
}
Funktionsmodell:
[Table("Functions")]
public class App_Functions
{
public App_Functions()
{
}
[Key]
public int Function_ID { get; set; }
[StringLength(50)]
[Required]
public string Title { get; set; }
public int Hierarchy_level { get; set; }
//public virtual ICollection<App_Controllers> App_Controllers { get; set; }*/
}
BaseContext:
public class BaseContext<TContext> : DbContext where TContext : DbContext
{
static BaseContext()
{
Database.SetInitializer<TContext>(null);
}
protected BaseContext()
: base("name = ApplicationDbConnection")
{ }
}
Funktionskontext:
public class FunctionsContext : BaseContext<FunctionsContext>
{
public DbSet<App_Functions> Functions { get; set; }
}