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.

2
  • You can use LINQ to SQL to meet your needs Commented Jun 5, 2014 at 8: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 Commented Jun 5, 2014 at 17:02

3 Answers 3

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).

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

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);

        }
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.