Of course you can, MVC and your data access strategy are two completely different things.
It depends if you're using Entity Framework or not. If you are, then you can map a procedure to an entity model within the designer, have a look here.
http://msdn.microsoft.com/en-us/data/gg699321[
^]
If you're not using EF, then it's quite simple - it's exactly the same as it's always been. You can just use SqlConnection objects (or whatever datasource you are using) and populate data
Here's an example of a controller creating a repository object which has a method that returns a DataTable. Obviously, you could have something here that returns a Domain\Model object or collection, whatever you like.
GetOutstandingInvoices
would be your stored procedur name.
public class MyController : Controller
{
private ISomeRepository _repository;
public MyController()
{
_repository = new SomeRepository();
}
public ActionResult Index()
{
var data = _repository.GetOutstandingInvoices();
return View(data);
}
}
public interface ISomeRepository
{
DataTable GetOutstandingInvoices();
}
public class SomeRepository : ISomeRepository
{
public DataTable GetOutstandingInvoices()
{
var results = new DataSet();
var connectionString = ConfigurationManager
.ConnectionStrings["MyDatabase"].ConnectionString;
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
using (var command = new SqlCommand("GetOutstandingInvoices", connection))
{
command.CommandType = CommandType.StoredProcedure;
var adapter = new SqlDataAdapter(command);
adapter.Fill(results);
}
}
if (results.Tables.Count > 0)
{
return results.Tables[0];
}
else
{
throw new ApplicationException("No data generated for invoicing");
}
}
}