1
I am trying to run a trial on ASP.NET MVC with Codefirst. I saw some examples on the internet but they are not working, someone can help me?
Follow the code I’m using, the Procedure just copies some data between tables and returns nothing.
public void Copiadados(int Cod_Cli, int Cod_Obra)
{
SqlParameter p1 = new SqlParameter("@Cod_Cli", SqlDbType.Int);
SqlParameter p2 = new SqlParameter("@Cod_Obra", SqlDbType.Int);
p1.Value = Cod_Cli;
p2.Value = Cod_Obra;
Database.ExecuteSqlCommand("ProcName @Cod_Cli, @Cod_Obra", p1, p2);
}
Why you have to run a Stored Procedure on an Entity Framework project?
– Leonel Sanches da Silva
When a work is registered, the billing of the work can be different from the customer’s data or not, when it is different the user marks a checkbox and the fields to fill in the data are opened on the screen, when the data is the same as the previous client will copy the data to the billing table.
– Alan Almeida
And this business rule is impossible to implement in a
Controller
? Some information that will be required for this copy is not recoverable by context?– Leonel Sanches da Silva
See, I can put the answer, but I want to be able to disagree a little bit more about how it’s being done. I believe that is not the correct approach to solve your problem.
– Leonel Sanches da Silva
I understand, is that I thought the best way was this, I could in the controller do the logic to search the data in the database and create an object and register this object, I did not expect to be too complex to run this process.
– Alan Almeida
I did as I said in the above comment, in the controller I search the customer data I need and register in the billing table.
– Alan Almeida
So. It’s best to put logic in
Controller
. Still, you want to keep this execution of Stored Procedure?– Leonel Sanches da Silva
No, I’ve already done it for the controller, but if you have the code for how to run the process and can put it here would be good, it may be necessary some day.
– Alan Almeida
Business logic in the controller??? Sorry, but are implementing wrong.
– Thiago Custodio