.NET 8 Web API & Entity Framework 🚀 Full CRUD Course (with Code-First Migrations & SQL Server)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey friends Patrick here and it is out there net8 has been released so this is now the perfect time to test it right and in this video you read the title and saw the thumbnail we are going to build a web API with all crud operations create read update and delete with all the HTTP request methods get post put and delete and additionally we will also already use Entity framework to store the data persistently in a SQL Server database I'd say we Dive Right In but first please guys if you like this tutorial and learn something hit the like button and please subscribe to my channel it does make a difference and shows me that you care and helps creating more videos like this one so please now just have a look at that subscribe button click there please please please guys it would mean the world to me and also thank you so much to all my patrons supporting me I love you forever guys and if you want to support me me to scroll a bit further down in the video description you find the link there so thank you very much already and now let's start with the tutorial all right here we are as you can see download.net and here it isnet 8 so of course I guess you already did that and installed the net 8 framework on your machine and you also have Visual Studio 2022 maybe of course you can also do that with Visual Studio code or jet brains writer or whatever you want to use but in my case I always use visual 2022 the Community Edition we create a new project and this is not the preview Edition anymore right so if you watched my earlier videos no preview Edition anymore this is the full official release and as you can see here it is aset core web API this is what we want to create same thing here today no Blazer stuff only a web API so we click next and of course as always I simply create a super hero API this time with net 8 all right we hit next there we have net8 long-term support again no preview anymore there it is authentication type none for this tutorial here https is great Docker is not necessary we enable open API support so we get swega out of the box this one we leave unchecked do not there it is whether to generate an explicit program class and main method instead of top levels nope and uh we want to use controllers so no minimal API because I'm a big fan of the classic controllers let's say so yes please use controllers and after a couple of seconds there we have our new project let's close that and not a lot has changed actually right so we have our controllers folder with the default example weather forecast controller real quick theet web acad Academy is currently open for enrollment but only for a couple of days meaning after this enrollment period doors are closed for at least 3 months so if you're interested we're covering pretty much everything you need to land a job as AET web developer meaning all the backend stuff web API Entity framework SQL Server front end of course with Blazer and also deploying all that with GitHub actions and Azure so if you're interested please check out the link in the video description thank you very much and now let's continue with the tutorial we have our app settings Json file the program CS as you can see quite small and we won't add a lot here actually only um Entity framework data context data base context registration using SQL server and here the weather forecast class but what's new Now by default you get this HTTP file so we also have the when you go to view other windows then endpoints Explorer you can open that you can click here and then with that you get to the actual method in your controller and you can generate a request now what is this thing doing it is looking for an HTTP file that has the same name as the project here right there it is and by default we already have well an example request and now we can click Send request for instance this is the new one now so let's just hit send request and well the app should be running of course so let's just run it and then you will see how this works but I can already tell you just a sec there is Swagger still right I can already tell you when we sent this request for the get HTTP request method that's nice because as you can see here you have your result there you also see uh the raw format the headers and the uh request header and body but see 200 okay this is nice but the thing is when you have and you will see that in well throughout this tutorial when you have post requests put requests something like that where you need data you have to send data to your web API then Swagger is still better because here then you will get example bodies example request objects already out of the box and so I still love this way here because here we will have a look if I don't forget it if I do please uh remind me and then I will add that here we won't get these default example bodies request objects you name it and I think this is well this is actually maybe the last thing that I would like to see here and then maybe I would use the endpoints Explorer with the HTTP file then but of course if you want to build your own documentation here and you want to have your fixed request objects not that typical Swagger stuff with the string text for a string parameter for instance then um yeah maybe this is the better I don't know it's up to you but this is actually the only thing that is new the rest is the same but still if you're new to uh building web apis with.net and now you want to start from scratch with net8 then you are at the right place my friend because here now what we will do is we create a little superhero as you already saw in the name here a superhero API or a Superhero Database for that we will also use Entity framework core with code first migrations or it's not called Entity framework core anymore of course it is Entity framework 8 in this case and uh we will use a sqrl server Express database so one step after another first thing we need is an entity for that well the weather forecast entities here at root level but I would like to create a little folder organize this just a tiny tiny little bit enti no entities let's call this entities or models something like that and you know we add a new item and this shall be the superhero all right first thing we need here is an ID all right and then I would like to add a name maybe this thing then is required all right then the next thing maybe is a required string for almost string for the name all right and then maybe yeah not the description but maybe we can set this to first name by default an empty string or you make it another would also work last name also empty and the place okay this is what I want here all right and now what we can also do already is we can create our controller so right click the controllers folder and we add a new controller not the MVC controller we want to build an API controller you have a couple of options here see even with Entity framework already and all the read write actions but what I really like is the empty one because then I can just do it all by myself and the way I like it to and it's as always the best way to learn if you just start from scratch and build up with every single method so now this is the superhero controller and bear with me here I am using a fat controller here all right in other videos and of course in uh other courses Web Academy and so on we will definitely use services and repositories stuff like that a better architecture of course but here now I really just want to give you a jump start tutorial a jump start lecture let's say where we use a fat controller meaning that we have all the logic here in the controller but usually it's true that you should inject at least a repository or a service something like that that then has all the logic and the controller would just forward the requests and then send or get the response from a service and send that then to the client all right just my two cents here and a little disclaimer so now for the controller what we want to do here is actually when we want to inject the database context then with uh using framework but first let's just create a little get methods returning a superhero all right with no database at all first so HTTP get is the request method we want to use and by the way again if you're starting from or if you're a beginner here with net8 and using or creating a web API what you see here these attributes they just say API control controller you can just hover over that and then you see it indicates that a type and all Drive types are used to serve HTTP API responses so this is a controller you can access this thing by using certain endpoints certain URLs actually you can type the them in in the browser actually right at the address bar of Chrome for instance at least for the get calls here and then you will see or you will get some data all right and here regarding the routes well as you can see here in the properties there is the launch settings jent file and when you start this here locally you will see that our application or you already have seen actually that this is our URL right Local Host and then the port 7111 great Port by the way always different only if you're using the net CLI then it's always the same but uh using visual studio here it's well it's always a new one so this time the application URL htps Local Host 7111 for this example and then when you go to your controller you will see API controller all right so now what you have to do is when we again have a look at the launch settings Chaser and we enter this URL and then when we go just jump back to the weather forecast controller here then you enter the routes and as you can see here they are different right you have the uh API term here then forward slash and then controller and the controller brackets just means that we want to use the name of the controller and the name is always the thing that stands in front of the controller term so superhero in that case or weather forecast in that case here so let's just try that real quick when we open that up so you see we started the application Swagger opens by default this is also a setting here in the launch settings Jason you see here launch URL is Swagger so then we will start here Swagger index HTML and this is what I mean when we uh try this out we can ALS also already see the example values although it's not 100% correct so just doing that because of the date only type here but you will see saw that already in the API or endpoints Explorer and the result now from from the HTP file but here as you can see it's the same dat looks not different right not the same stuff you see here but you also see the request URL and again you can just copy that for instance and enter it here and you also see that data and by the way you can also open the network Tab run this one more time hopefully oh no not I filtered for fetch xhr which stands which stands for XML HTTP requests but here now we are entering that stuff in the address bar so this is different you're making a call though but uh you have to filter for well nothing or all and then you also see the actual call here with the preview right this is better formatted so you can open that up you see the response not formatted and so on so this is just a quick quick uh introduction to all that here and now we want to build our own API so let's go back to the super superhero API here this is the controller again and the first method maybe it looks like that so a public acing task returning an action results you could also say uh we just want to return an i action result all right and say get uh all heroes like that and then in here we just return or let's create a new list so bar Heroes is then a new list of superheroes like that and we just start with one superhero here all right so new superhero and yeah ID is one name Spider-Man first name Peacher last name then you know this right and the place New York City all right and then here we return we could just return the heroes here or we use okay and then Heroes and this then will return the status code to 200 and this means then everything is fine all right pretty sure you all already know the return type 404 right this thing here this means not found everybody knows that even people that have nothing to do with programming or coding or web development they know 404 means there's nothing there so here now superheroes you see it this is our get call we can try this thing out but what what you maybe already see is that we don't have an example value here and our type is not mentioned here in the schemas but still when we execute this thing we get our result this is great right but maybe for our documentation we want to see what can we actually expect here we don't want to try everything out we just want to see what what may be is the result and this is where this thing comes in maybe if you want to see the actual type then you could Define it with acttion results not the interface actually the implementation class and then here we say we expect a list of Super Heroes all right and we add one more angle bracket and maybe make this a bit smaller here don't know why I have this at that size and that's it let's just uh restart our application again there we are and now you see the great superhero type here isn't that nice and here now we can wait scroll a bit further down down and we see the example value and in that case this is true and now you also see what I meant with the string text right it's the same thing when we try to create a new superhero all right then we see default values and in that case in Swagger at least we would see a string so what we could do then is we just try out the post request method and we get this thing here that you see here as example object just hit send you don't have to type anything and uh with that we can test if this then already works we execute the stuff again and we get Spider-Man but no database so far one more thing I uh still want to add here when you refresh this now we see out of the box okay there's a new endpoint for us all right and this is great right so that this works and that they've edited here so if you want to stay in Visual Studio then maybe this is a great new way to test your API calls all right we can here generate the request right send the request and get the result there's Spider-Man isn't that nice all right HTTP file yeah save it why not and this is the get call but now what I want to do is actually use a database right because this is well can do that to play around a little bit but I want persistence here so let's add a database for that I create a new folder and this folder folder is called data and in here I create a data context so data folder data context why is it called data and data context well to get some data and store data in a database so much data and we inherit from DB context so the data context inherits from inherits in yeah English inherits from DB context or database context and for that as you can see red squiggly line here but if you press control and period on your keyboard then you get this quick fix menu you could of course also click on the light bulb but here then it says install package Microsoft Entity framework core find and install the latest version and yes please do that Visual Studio because with that we get the latest package for net 8 isn't that great and here you can see Microsoft entity frame cor now version 8.0 point or o or the brand brand new stuff love that and uh yeah you see that in your projects file then all right so with that we got entry framework and now back to the data context and you see that uh no red Squigly line here anymore right this is amazing but we are not done here we first need some boiler plate codes and the first thing here is a Constructor so CTO o r and then we hit Tab and here now we use a parameter called DB context options of our new data context we call this options and we also run the base Constructor here with these options and additionally what you want to add is a database set so we add another property again call this what the type then is DB set of type super hero almost super hero again control period to add the using directive here that's that should be the one yep and then we give this thing and name and this then will be the name of the table that represents the superhero entries so usually you would just pluralize that thing or the class name in our case it's superhero so maybe superheroes would make sense so why not do it and it's already suggested great stuff so this is everything we need here what we also need is a connection string and we could add the connection string here but maybe it makes more sense to put it into the app settings Json file so this file here right or somewhere else environment variable something like that because in the end when you want to deploy that to Azure for instance then well it's better to do it that way instead of maybe hardcoded right so we could also use the unconfigure method here to configure some stuff or again we just use the app settings Json so let's do that real quick and here then we have see it here it's already suggested the connection strings section and by default we just call this default connection and then it's getting a little bit complicated this is different maybe on your machine but if you're also using SQL Server Express and by the way if you haven't used it before then you just Google for SQL Server Express and then you get here then you can go to SQL Server downloads and then you scroll a bit further down and of course you could also just use the Developer Edition here or the express Edition both are free download this thing and then you will also get at the end of the installation a suggestion to download the SQL Server management Studio or again you just Google this thing secret server management Studio there it is download secret server management Studio this thing is also available for free and there it is and this is just in my opinion a great tool to well manage your SQL databases SQL Server SQL Server Express databases all right enough about that now if you did this you need a connection string and this then looks pretty much like that so first we need to set a server and that would be period back slashback slash and then SQL Express then we set the database name so database equals and then maybe super hero DB all right after that trusted connection to true and since doesn't seven we also have to set trust server certificate also true and that's it all right so server secret Express database super hero database trust connection true and Trust server certificate also true so this is now our connection string our app settings Json file great stuff but now we also have to register the database context or our data context and then also tell Entity framework which provider to use and in our case the provider would be SQL server but one step after another here real quick the program CS it is small this is great so what's happening here well I think the most important part is we'll be building a web application here and then you see these add controllers methods and also down here map controllers so this is important for using our controllers we have the endpoints API Explorer all right and then also not necessary but in my opinion still important and very useful Swagger so our open API stuff and here as you can see when we are in our development environment then we add Swagger with the Swagger UI so this is the stuff you already have seen in Chrome right so with that we can test our API we use htps to redirection see it here this is all middleware stuff so all these use methods here are middleware this is middleware for redirecting HTTP requests to https middleware for authorization stuff and in the end we run the app right I really don't want to dive too deep into that but this is in essence what's going on here in the program Cs and you will have to add lots more stuff later for instance when you really use repositories or Services something like that you want to use other middleware you want to use other packages you want to use identity for instance for authorization authentication then you would always come back to the program CS here and well add some lines all right so maybe adding a service would be then Builder services and then you have the options to add them as a scop service transient service or Singleton service this is also dependency injection stuff made a video about these three options here so maybe you want to check out the info card but for us now what we want to add what kind of service we want to add is the DB context but we want to use the add DB context method for our data context and then we can give this thing options which first we add the using directive and then here what we can do is you just say options almost options that's the one and then curly braces we say options and then use SQL server and we don't know this method yet because we have to add another new get package and then we add our connection string from the app settings Jason file so here also you could hardcode it of course but not the best practice maybe so here what we can do is build ER configuration get connection string you could also use the options pattern by the way I will link to that video also here in the info card so connection string and then default connection all right and that's it and now here we cannot use control period virual Studio has no idea what's going on here so let's just save that and after that we right click the pro project at uh or manage new get packages and then add and you get you get package and simply enter SQL Server maybe server like that and here then you see Microsoft Entity framework core SQL Server the Microsoft SQL Server database provider for Entity framework core version 8 so we also need that for SQL Server Express and when this thing is installed we can actually go back to our program CS there it is and now again control period or the quick menu as you can see here and then we add the using directive or the reference rather Microsoft Entity framework core and that's it but there's one more thing we have to add regarding the new packages for our code first migration so we actually have two options now we could use the net CLI with the uh net Entity framework core tools install these or because then this thing is available globally for every prodct project and I did that in other videos but maybe just for a change we use the tools here just for that specific project so here you see Microsoft entty firm core tools you have core tools for the new get package manager console and visual studio because when we install this thing then we have commands available to add a new migration to update the database stuff like that all right so now when everything is going away now we can do the following we have the DB context registered here we have our data context here we have our superhero type so this should be everything we need to add a migration right so let's try that but first we have to stop our application for that I just open the terminal there it is and close this and now I open the package manager console and one thing that's already different to using the net CLI here is you do do not have to be at a specific folder so if you want to use the net EF core tools then you would have to change your directory go into the superhero API donet 8 folder for instance but here now what we can simply do is add- migration and I hit tab so that's because we have the capital A and M and then for instance let's just call this initial build started this is making me nervous every single time build start uh build succeed this is nice okay this worked and here it already opened the migrations file this this is new love that because I always want to show the migration file after uh adding a new migration so now what you can see here we have this new folder right migrations we have this data context model snapshot this is just internal Entity framework core stuff or Entity framework a stuff entity frame stuff we don't really don't have to look at this file actually we will also have a history table in the database then also not really necessary to have a look at that except you have some you made a mistake regarding the migrations you updated the database and then you have to roll back then maybe you have to delete an entry from the history table but this is for another video maybe but now here the initial migration what you can see here we have two methods an up method and a down method now the down method this will be executed when you roll back that migration in that case it will drop the table superheroes this means in our up method we will create the table superheroes and also as you can see here with the given types and it already knows that the ID maybe should be the primary uh column or is the primary key then right so here's the ID we have uh automatic well it increases the ID automatically this is nice and then well and Bara Max for all the strings name first name last name place and so on this looks great to me now let's try to update the database so for that we enter update nope that was too quick update database even if the database does not exist and I think this will not work but let's see yep there is an error and why is it only the invariant culture is supported in globalization invariant mode what the heck is that well if this is not important to you then there's an easy fix and in my case it isn't important to me so we just go to the project file and here you see this entry invariant globalization set to True let's just set this to false try one more time update database build started build succeeded that was fast and now we see all the commands that are executed here you see this is the history t table inserting something into that history table and here you see it will create the superheroes table great stuff it worked so now let's have a look at the secret server management Studio there it is we refresh our database or our server rather time tracker database from the doet Web Academy you can ignore that but here now in the Superhero Database tables youf migrations history superheroes with the given columns see see it here ID is a primary key we can for instance edit the top 200 rows and this means we see nothing because of course we haven't added anything here no seaing whatsoever but we can add something here now so for instance what we can do is enter a name Peter nope this you know is Spider-Man with Peter Parker and again New York City and we get the ID One automatically all right so this is now our table our database working we have one entry here all right so now we can make changes to our superhero controller well I already set the term dependency injection and this is what we will also do here we will inject the data context now into the controller again short recap this is a fat controller this is not the best practice I have to say that again but for this quick tutorial which isn't that quick actually I just want to emphasize this here that usually you would for better practice work with additional services or repositories but here now just to give you a jump start I will use this fat controller with all the logic here inside of the controller already but still the way you you do this is very similar let's just say we want to inject our data context so private readon data context we name this context for instance and then with control and period we see the option to generate a Constructor here with that parameter this is great let's just do it that way and here you see that the context is now injected now when you would use a service for that for instance a superhero service or a superhero repository then you would pretty much do the same thing but you would then inject the data context here in that repository or in that service and then in the controller you would inject the service or the repository all right I hope this is clear now if not just ask in the comments please and then I'll do my best to answer your question all right so now we have the data connects available and let's just change our HTTP get method shall we so here now what we can do is instead of Heroes is this new list we can just access our superheroes table and we do that with a wait and then context almost context and then we have our beloved superheroes here available and then we just turn that into a list like that all right and then here we return Our Heroes shall we try that maybe so let's just run this there we are let's refresh this just to be sure we open that up all right try it out execute and and same result right now maybe let's just add another one so here know Iron Man Tony Stark and the place was Malibu I think and now pay attention here I did not go back to visual studio and restarted the application or anything I just made a change in the database right so still the same application I even do not have to refresh this I can just hit execute and there's Tony Stark isn't that nice all right but now we don't want to change our entries in the database right we want to do that with our API so what we can do here is we just Implement all the crowd operations meaning we have get already to get all the heroes now what's missing is getting a single hero by specifying an ID and then we also have creating with the request method post updating with put and also then deleting well with delete of course so let's just copy that thing and now let's get a specific hero so now let's just call that get hero with an ID all right and now this ID is of course a parameter but here now says it here we also have to specify the ID in uh in the route somehow so what we can do now is actually we could use the exact same attribute here the route attribute so like route and then in parenthesis we just specify the route something like single hero you could use but this is not really rest style right so what we can do here is in curly braces we specify this is now a parameter and our parameter is the ID so these two have to match or we can just grab that put it here and combine these two attributes because if we don't do it like that so let's just say we we remove the route we save that we restart the application error right because here now we don't know we have two methods in the same controller that are using the HTTP get request method so the route would be exactly the same for both and our web API has no idea our web service has no idea which method it should use so please make sure to add the route then there and you know well we just want to get a single superhero so how can we do that well again of course our context our superheroes and here now instead of two list async we just say find async with the given ID and what we can then do is if the hero yeah it's only one hero in this case of course so if the hero is null or is null totally up to you actually then we return well told you that earlier right and not found for instance or if you want you could also return a bad request and then here add a message like hero not found again this is in the end totally up to you all right so now this Returns the status code 404 B request would be 300 but if if we find the hero then we just return it so let's save that restart it again now we have two methods here and as you can see with one we get Spider-Man with two we get Iron Man and with three we get a 404 hero not found and again just for demonstration purposes here bed request restart the application and here now we add four four and this time sorry I said 300 of course it's 400 this time we get 400 hero note found so all the 400s are the error uh status codes right in B request is also then the 400 401 would be unauthenticated 43 forbidden and so on all right so now again not found maybe and on the next thing maybe could be post so we want to create a superhero all right so again let's just copy that and you now we add HTTP post here we can say add hero and now here also not always the best practice but again it is great for a quick tutorial we enter the superhero class as a parameter what would be better maybe is to really create a separate request op object or a dto a data transfer object where you then put only the data or said only the data that you actually really want to uh see in your in your request for instance if you would now here go on let's go to the superh hero class if you would here have dates like date created Date Update stuff like that or actually already the ID the ID is actually not something we need for create creting a superhero so you would create a dto a request object another a separate class only with these properties here for instance send this to the to the web service and then the web service would map the data from your request object to the actual entity and then create this new entry in the database all right again just so you know quick information here and one more thing I just saw this is not correct so let's fix that real quick all right I know you saw that right you you were yelling at the screen and saying Patrick pay attention here this is wrong dude but it still works that was interesting right so did I really make this mistake or did I want to show you something interesting here think about that all right so now HTTP post add hero superhero hero so many Heroes and now what I want is actually just create that new hero so what we can do here instead of all that we just say context superheroes and then add and then hero all right so now we will get a hero out of that and just uh again return all of them but first really important this method here this will not save that change okay this will just as you see it here it begins tracking the given entity but you have to call Safe changes or safe changes ring if you really want to store this new hero persistently in your database so then await context save changes async and in the end we can actually return all the heroes because here know the return type right is the list of all heroes so maybe just wait get not hero get all heroes all right real quick told you that earlier but here now when we refresh we see the the post method and we now say generate request this is what I meant I just have this little comment here and well when I send this request what will happen it does not work the body is not correct and the body that's actually also a a good hint so before here with the um get method this parameter was used in the URL right but here now this comes from the body maybe you've also so seen something like that here before so this is an attribute telling the web API that this should come from the body but with that complex class here the superhero this is not really necessary it just assumes that it already comes from the body and this is absolutely correct because again when we now restart this thing then we see this is our new call and when I open that up you see here this example value and also the reest body we also again again get example values here so we could actually just hit execute and we're done or we just enter something here so maybe we have Hulk or no let me let me add another one Batman of course Bruce Wayne Gotham City all right we execute and what did I do wrong ah of course this does not work again why didn't you tell me guys I was thinking in services so when you have a service of course you would not return okay Heroes you would actually return the heroes and then of course you could also use this method so what we can do here now the options we have is either extract this in a separate method or we just copy paste that stuff put it here and we're good to go so let's try that one more time and now we have the option to add Hulk try that come on Hulk it is another Bruce Banner and the place I actually don't really know but the birthplace is Dayton Ohio so let's just use that one we had execute and now we got all our heroes and as you can see Batman was also successful so we were able to create Batman sorry for these uh little mistakes here but you know maybe this is a great way to learn right so post also works but the next step now is updating Heroes and as you can see I made again little mistakes here because this is not 100% correct how you write Spider-Man or Iron Man so maybe we can change that and for that now we create the put method so HTTP put it is now here we have two options we could also add the parameter the ID here in the URL or we use again the complete superhero object here call this method update here and then grab the ID from that object check here because what we want to do is first you want to find the given hero with the given ID in the database and if we find that hero then we will change the uh Properties or the data and then uh save that and return again the complete list of superheroes I hope this makes sense so update hero it is and also by the way maybe you will also see in web services that with uh creating here add hero and update hero you would not actually return the complete list of superheroes of course because maybe you have hundreds of thousands of millions of entries so actually you would maybe return nothing or just a success message something like that so this uh is not always the best way to do it of course but again I know I'm repeating myself I just want to show you in particular for beginners how you well get up to speeds with building net web API with net 8 now okay with that out of the way again uh let's try to find the the given hero so we did this actually already so here now let me just copy that paste it here so we try to find the hero but the ID is now in hero ID and this is now the DB hero for database hero and then hopefully yeah the eror is gone and now if the hero oh almost if the hero is null we do that but otherwise we map that stuff DB hero name then is the I call this is the hero name maybe we can change the name here actually and call that updated you could call that request maybe or updated hero stuff like that something like that and then uh we want to change also the first name all right and this shall then also be the first name then the last name all right and then the place is updated hero place okay again we have to save these changes so context save changes async it is and again we just return all the heroes so let's restart the application again we see now in Orange this is our putut method try this out and now you really have to pay attention here maybe we do something else first so because we overwrite well pretty much everything apart from the ID so now here for Spider-Man this should be ID one right so maybe we can just uh copy that and then here input paste it and this is actually now Spiderman like that right so execute and we see this is not correct we could also call Spider-Man though Amazing Spider-Man because Spider-Man just is really amazing all right and Iron Man same stuff so here now copy that paste it here and it's actually that way all right execute that's it nice so now again a look at the database we right click and execute SQL and here are our beloved superheroes isn't that nice all right now the last Crut operation the last method we have to write is the delete method so get is here for all heroes get for a single one creating with post updating with puts and now let's just uh remove one hero so in that case we will use delete as HTTP request method we can call this also delete parameter again an ID like that and we try to find this guy of course with the given ID same thing and instead of setting the properties now we say context Super Heroes remove remove there it is DB hero and again this method doesn't actually change anything again it just begins tracking so we have to call Save changes async to make this persistent save that restart the application and now in red because it's really dangerous try it out and what about five execute here we not found okay worked four yep Al was deleted now we only have Amazing Spider-Man Iron Man and Batman of course so now in the database again refresh that's it great so I hoped you learned something guys and if you did and like this tutorial then please hit the like button please subscribe to my channel it would mean the well to me and thank you so much to all my patrons supporting me this is how this channel can grow with all your subscriptions likes and of course your support on my patreon page check out the link in the video description below if you want to support me too now I can only say check out these videos here on the side and there's a lot coming regarding Blazer of course and net a so stay tuned maybe you really want to subscribe thank you very much for watching and I'm really looking forward to seeing you next time take care
Info
Channel: Patrick God
Views: 19,496
Rating: undefined out of 5
Keywords:
Id: b8fFRX0T38M
Channel Id: undefined
Length: 50min 44sec (3044 seconds)
Published: Tue Nov 21 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.