Thursday, June 4, 2015

Executing MySQL sub routine in Entity Framework

Entity framework has an easy and slick way to support MySql. In MySQL stored procedures are called stored routines. Routines can be called from Entity Framework using below syntax:


using (var dbContext = new DatabaseContext())
{
  var subRoutine = string.Format("CALL StoredRoutineName('{0}','{1}')", value1, value2);
   signInAttempts = dbContext.Database.SqlQuery<int>(subRoutine,
                     new MySqlParameter("value1", value1),
                     new MySqlParameter("value2", value2)).FirstOrDefault();

}

1 comment:

Chandra Sekhar Kosuru said...

Hi,

I seen your solution, Seems to be good... Same solution i got where i searched for solution.

Before fixing this issue, I want to reproduce in our Local/ UAT environment. Did you have any idea... How can i reproduce this issue. Currently my projected using same EN-6.

Thanks
Chandra Sekhar.k