0

Guys I am trying to learn MVC and I want to use stored procedures to perform all CRUD operations in MVC framework. I have googled for tutorials and everything, but all the tutorials are using that "Code-First" approach and using Entity Framework to handle all the data.

I would really appreciate if someone could help me regarding how to use SP in MVC and could provide some links to tutorials or something like that.

tereško
  • 58,060
  • 25
  • 98
  • 150
NewbieProgrammer
  • 874
  • 2
  • 18
  • 50
  • You can use LINQ to SQL to meet your needs – Arijit Mukherjee Jun 05 '14 at 08:16
  • Just make sure you separate your data access. Some example may show putting ADO.Net code in the controllers directly. A repository pattern is a good first level of abstraction, without exaggerating. Then if someone comes along and calls you an old bugger for not using EF, they can just replace the Repository implmentation without rewritting the web app. See also [Using MVC with ADO.Net](http://stackoverflow.com/a/6694195/458354) – mdisibio Jun 05 '14 at 17:02

3 Answers3

2

Before you learn Entity Framework, before you learn LINQ to SQL, take the time to learn ADO.NET which is all you need if you want to call a stored procedure. The previously mentioned technologies are in fact built on top of ADO.NET so it's good to know what they are doing. Check out lesson 7 of this tutorial which shows you exactly how to call a stored procedure from any .NET application (including MVC).

Jason Nesbitt
  • 730
  • 1
  • 6
  • 15
0

You can always use code first from your db Code First to an Existing Database

Danny
  • 301
  • 1
  • 4
  • 21
0

Using this simple method, I was able to call stored procedures in MVC application

public static DataSet ExecuteDataset(string connectionString, CommandType commandType, string commandText, SqlParameter[] commandParameters)
{
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        connection.Open();
        using (SqlCommand command = new SqlCommand())
        {
            command.Connection = connection;
            command.CommandTimeout = 0;
            command.CommandType = commandType;
            command.CommandText = commandText;

            if (commandParameters != null && commandParameters.Length > 0)
                command.Parameters.AddRange(commandParameters);

            return FillData(command, connection);

        }
    }
}
NewbieProgrammer
  • 874
  • 2
  • 18
  • 50