Dapper CRUD Example with Stored Procedure in ASP.NET CORE | .NET 7

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone welcome my channel asp.net core and today I'm going to teach you how to use Dapper and uh current operation of dapper in asp.net core okay so uh first of all just open your SQL Server management studio and create a simple class that it's students and how to create a table uh in SQL Server management Studio that is very simple just create a new table and here we have the design of the table that is the ID and the name that is ID is the type of integer and the name is the type of and variable type of character that is 50. okay so here we have some data in a table uh that is the student table and here we have some data so here we have a table that is the student and here we have some data in this table that is read top 200 rows so here we have a data and just I'm going to use this table uh in uh in SQL Server management 2 in user studio so just create a new MVC based application and here we have just create a new model that is the student first of all that is public student ID in the name okay and this that is the DQ you can say that or you can say that that is a view model okay now uh on that view model just add a connection string in the app settings.jection file and here we have the Json file is a connection string default connection server local dbms equal local DB database just like that trusted connection and multiple active visual sets after that uh you can just register it in the program.cs file looking like that so here we have a builder dot Services dot add transient and just you can use idb connection options dot options equals to new SQL connection Builder Dot configuration.getconnectionstring and the connection string name is the default connection okay so here we have a connection string name that is the default connection okay now just after that you can just go to a builder.configuration.cat connection string okay and here we have a idb connection that is the part of the adapter okay so just you can use a uh package that is references packed that is Dapper and also you can just add the new package that is system.data dot SQL client and in the program.cs file here we have a idb connection that is actually existing in the system.data that is namespace and here we have a new SQL connection that is existing in the system.sql find okay so here we have a connection string that SD called dot default Connection in the existing in the app settings.json file now in the controller section just use idb connection so here we have a controller that is students controller and here we have a private idb connection context and there is not a DB context there is not a part of uh you can say uh it's it's not a part of your Entity framework it's a part of dapper so that is the instance name only so here we have a connection context or initialized in the dependency injection and in the index just get students and context.query in the student and in which you can just pass stored procedure name that is get students and here we have a stored procedures that is the stored procedure cat students insert students and uh and many more just research it the DB and you will you will get that the old uh the stored procedures okay so here we have a stored procedure name that is the parameters and the command type is the start position so just uh after that get all the students similarly we have the create and the create post and in the create button uh in the create post here we have a dynamic parameters like that and just add that Dynamic parameter in the form of a student.name in the type of db.db type dot string and here we have the parameters and insert the students just I want to get only the name in the insert parameter similarly ID on the basis of the insert here we have to call the adapter that is execute okay and the similarly if you want to get the item from the database then you can use Query first or default if you want to get single item from that database table so here we have the student ID and just pass it into the view section okay and here we have a dynamic parameters in the form of the ID so these are a database that is student and here we have these are programmatically and here we have stored procedures and these are the stored procedures so wait for some time it's expanding and the next one is a HTTP get HTTP added post that is the student and here we have two parameters that is ID and the name so execute update statement with the parameter and the command type is stored position okay so everything is fine now that is the controller and here we have a these are stored procedures get by ID get student insert student and update student you can just add a single store procedure to get all these things okay and after that you will just call it https and you will get that uh that is the quickly response instead of Entity Framework so you can use Dapper if you are use micro services so just you can use dapper Okay so okay so here we have the students and index and just after that these are the names instead I'm going to create uh John the name so here we have the Zone just I want to edit it in Jerome Smith the name so just save this Thomas method okay so everything is fine now just I want to delete this part so just delete the ID number six so you can just uh use any query and create a stored procedure for that lead create procedure procedure name delete student that is the processor name and as a ID on the basis of the ideas I want to delete it so integer and as begin and delete from students and you can say that delete from the students and where ID is at the rate of ID that is the parameter so the parameter of his name is like looking like that and just after that and the stored procedure so just you can use and after that you can use delete student here okay no and in the context just you can use so stop this stock procedure and here you can just use HTTP cat and public and result delete user ID and here you can just use a directly you can use context Dot uh execute and in which you can just pass a stored procedure name delete a student and the parameters and the value of the parameters Dynamic parameters and the parameters dot add ID and ID and DB type Dot in 32 so here you can just use parameters stored procedure and you can say that command I it's a type of command type Dot stored procedure so everything is fine now after that you can just use return redirect to action index so save this and you will say that the every item will be deleted if you just call that delete method on the basis of the ID so that is the part of the service that is the part of the tablet you can use it in your project and to just get it anywhere everything okay so wait for some time it will be run after a few seconds and you will get the output result okay so here we have the results index and this I want to delete the zones everything is fine thank you guys for watching this video and keep watching all other videos which is related to asp.com
Info
Channel: ASP.NET MVC
Views: 2,761
Rating: undefined out of 5
Keywords: Dapper Service, Dapper
Id: mJal-dYST5I
Channel Id: undefined
Length: 10min 38sec (638 seconds)
Published: Mon Jul 24 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.