none
How to use multiple modes in one store procedure? RRS feed

  • Question

  • i want i write a Store procedure and in this i have to write multiple modes like insert update and so on. no if i get data from this SP in MVC so there is automatically generate class like SP_ABC_Result  and its auto properties set. now how can i get this. 
    Thursday, June 20, 2019 6:33 AM

All replies

  • Hi Mohsin_

    Since this thread is related to mvc, I suggest that you could post it in the following forum.

    https://forums.asp.net/1146.aspx/1?MVC

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 20, 2019 8:26 AM
  • i want i write a Store procedure and in this i have to write multiple modes like insert update and so on. no if i get data from this SP in MVC so there is automatically generate class like SP_ABC_Result  and its auto properties set. now how can i get this. 

    Yes, you can do that with a Stored Procedure and have the classes written for you by writing your own Object Code Generator that would do it. You don't have the expertise for that I would suspect.

    On the other hand, you can use the ADO.NET Entity Framework, an ORM,  that you can configure to work with Stored Procedures and create the classes for an existing database the EF would be using by using EF Code first for existing database of use EF Database first for existing database.

    https://www.codemag.com/Article/0711051/Introducing-ADO.NET-Entity-Framework

    I also suggest that you learn ASP.NET Core MVC  and EF Core.

    As mentioned ASP.NET issues can be discussed at the ASP.NET forums

    http://forums.asp.net/

    Thursday, June 20, 2019 10:28 AM
  • Why would you want to write a single stored procedure that did all of that? That completely violates the SRP. Would you ever write a method that handles CUD as well? What exactly do you gain by doing this? If you have complex logic that would be repeated in each "action" then move that to reusable code (a separate sproc or function in the database).

    By having a single sproc in the DB you make it very easy to mess things up unless you have very good constraints. For example if you have a shared insert/update sproc and you look at some sort of ID on the data to determine whether it is an insert or update then you are completely reliant on the calling code not forgetting to set that ID. If they do then you may add when the code was expecting an update. Furthermore the data you pass to insert/update/delete are generally different. For example an insert you generally pass the data and get an ID back. For update you pass the ID and the data and get nothing back. For delete you generally pass just the ID. A single sproc that does all this would have to account for all those combinations.


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, June 20, 2019 2:04 PM