Naresh Seth

Naresh Seth

  • NA
  • 84
  • 1.8k

How to create Stored procedure in Entity framework?

Jul 5 2018 10:41 AM
I am trying to create stored procedure in Entity framework using context class. We have one method Up() in Dbmigration class, which we can use to create Stored procedure. But We can't inherit two classes.
 
Any suggestion would be a great help.
 
public class CustomerContextInitializer : DropCreateDatabaseAlways<CustomerContext>
{
public override void InitializeDatabase(CustomerContext context)
{
base.InitializeDatabase(context);
if (context.Database.SqlQuery<int>("SELECT COUNT(*) FROM sys.objects WHERE type = 'P' AND name = @uspname",
new SqlParameter("@uspname", "GetCustomers")).Single() == 0)
{
{
}
protected override void Seed(CustomerContext context)
{
IList<Customer> cust = new List<Customer>();
cust.Add(new Customer() { Name = "John", Zipcode = 98052 });
foreach (Customer c in cust)
context.Customers.Add(c);
base.Seed(context);
}
}

Answers (3)