Asp.net core Scaffolding - Course to learn developing Web Application

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody welcome to digital tech join in this video i'll demonstrate how to create a simple web application using scaffolding so scaffolding basic is a code generation framework it's like a wizard provided by microsoft to enable you to interact with your data models and create a standard data operation application quickly without writing a single line of code so let's check out how this is achieved so let's open visual studio 2019 click create new project select asp.net core web application click on next a demo app and i've selected my default location click on create make sure that you select web application model view controller during this video i'll also introduce you the concept of model view controller and how the design pattern is adopted just a summary on that topic make sure that you and take this configure for https and click on create so project is getting created so in this i'm going to create a model for maintaining book information basically titles so so what we'll do is that project is loaded first thing we'll do is that we go to our data model folders and we'll create a data model as and name it as titles so we add a class like this and now we set some properties it's as good as designing a table and adding columns so we create properties so we say prop double tap this is a feature of dot net we can use this to quickly create the properties so our first it will be an id because this will act as a primary key of the table or the data model then i will tap this will be string tab and this will be title name and then we will have drop double tap string we can have uh isbn number so we say isb en number i think it should be inked and then we have property string sorry it's it will say cost and then we have obviously the author name string author name and then we have the last field string and public string publisher name so our model is ready so it has a id field it has title name isbn number cost author name and publisher what is the next step now our module is ready now we will go ahead and we'll tell visual studio asp.net core to enable scaffolding for that what we'll do is we'll go to the controller we will add a controller called title make sure that you use mvc controller with view using entity framework so this is very important so once you select this now pay attention to this to the screen when it says model class which we have already added which will be our titles okay now data contest class is nothing but it is it is a class that will interact with your database uh i have created videos on data context class you can go and watch it out uh we will simply here say add because we are creating a new data layer object or class and we call it as demo app dal or we simply say dal app or that demo app okay so that is data access layer so we say that and we say add now this is a controller class this is our we are going to create a new dial now what visual studio asp.net core will do is that it will add the necessary packages and set up our project with all the features for titles class just see add you can see it is using the new get packages and installing the entity framework core then it will install all the dependency injection it will install the data layers the compatible database which we can use and during this video also show you the inbuilt data migration how to use the command of data migration and set up a database everything will be shown in this report so please be with with till the end and watch every every action and every setup which i am doing it so that you understand it thoroughly and believe me this will be your core uh you know uh concept which will enable you to develop much in bigger enterprise application so what i what has happened is that now if you look at the project we have a controller class which we added we have a data model now we also have a data layer which is dal demo app what does this do this is having a constructor and it is having a declaration of a model so this represents our table so so titles is a table okay now if you look at the app city.json you will also notice that it is added a connection string it is added a connection string and it is named the database as that demo app contest and with some alphanumerical number so this is automatically visual studio or asp.net core as set up this database but this database is presently not created we are going to issue some commands and create the database and we can visually see it so how are we going to do that because if i run this application right now you will see you'll get an error or you might not get an error because i have not yet initiated the the command or written the code to call the project so so right now it is it is not having any error but but if you look at the controller and if you look at the view okay now when we created a controller for titles over here it created a controller title and if you notice it is created a titles view with all the operation we're showing the data editing data delete data details and creating a new title now i'll explain this class i've explained this entire concept in detail in my previous video but today's video is how you can create a standard up web application without writing a single line of code now see this is what the dot net is done for you ac dot net core is done for you it has created everything for you now we need to go ahead and set up the necessary tables so i will go to this class view shared and instead of home over here what i can do is that i will call the controller titles i want to show the error to you so that you understand titles and titles as a page called index so now we will run this project and click on home and you see we will be thrown with an error because it will go and find the database which is still not created so you can see the error so let us fix this let us fix this error by creating the database so go to your tools nuget manager and go to console here we first issue a command called add migration and name it as initial migration you can name anything so look at the folder over here see it is created created a fold folder called migration okay and it is created a file okay which will actually create a database in the table okay so now if you look at if you open this migration file you can see that it is created a table okay with basis model class which we created id title name isbn cost author and publisher name and its defined primary es id so the table is created it is set up the table and this is the data context class which is created this will actually go ahead and create a database with all the constraints required now we have created the class now it's time to execute it so go to your package manager again and say update database succeeded now if you go to your view and sql server object explorer will be summarized to see a database is created for us automatically with all the required columns i'll just open it so you can see the sql explorer now this is where our database is if you click on database this one database and here you can see demo app and it will have dal demo this is our database and this is a table which is build basis or data model which the model class which we created a refresher difference sticking to that dial demo app and this is a table way too much of time i'll notice yes so we can see the table titans is created over here and you can see view data right now there is no data now let's move to the next step we will try to run this project and we will be surprised to see that everything is already built and set up for you so we click on home this time there is no error because the table is created we say create new title cost author named publisher update we say create yes the data is created let's create one more so you can see the we are able to create a new title book we are able to edit it we are able to view the details we are able to delete the book everything is said i have not written a single line of code to achieve this now if you look at the database you if you look refresh the database or view data you will be able to see that the records is available over here so i have done nothing okay everything was done by the asp.net core scaffolding code generation framework it created a necessary data layer to connect with your data class it it has created a connection string over here here you can see it has created a connection string over here it has added the necessary startup code so that your project knows which database to connect when it's run so this is the way it is created uh pulled the connection string from the app setting and connected to your database so everything was given done by dotnet i didn't write a single line of code to achieve this now coming back to our mvc pattern what we can see over here is in our view we created a model and then we created a controller called titles and that title controller added all the necessary methods method to fill in the information from the database to view the details to create a new view new title and to edit the title to delete the title everything all the codes were generated by the code generation framework also we can see that in the view model bases the type controller name it created the set of all function by default like it for create for delete details edit and index everything was created by the scaffolding code generation engine coming back to our understanding of mvc i'm sure everybody knows what the nvc pattern is is famous for but let me just walk you through once so what what is what is an mvc the basically an mvc is a framework it's a design pattern that separates an application with three main logical component that is your model view and the controller mvc separates the business launching and presentation layer for each other the architects become popular for designing web application as well as mobile app and it provides way bigger advantage over the traditional monolithic design architect coming back to our architect the visual architect of mvc we have three main competitors called the controller view and the model the controller interprets the request and response from the user and then it it connects to the view and the model the model connects to the database so that offers a great level of separation of logics and that is why it is it is it is faster development is faster multiple developers can work and this provides a very clear clear segregation of component the roles and responsibility which each component plays which is a very vital and very important and that is why mvc is becoming so popular now if you look at the features it has as i mentioned offers a clear logical separation supports the test driven development now why the supports are tested alone because it offers uh the model and the view and and the controller can be separately tested and codes can be written against those component without without any impact to the other components in the in the in the patents multiple developers obviously can work it offers a faster development process and obviously we should not forget the advantage and the great use of routing uh which which which has uh totally removed uh the need for physically pointing the files in iis uh like we used to have previously in a traditional asp or asp.net so i hope you have understood this uh concept i hope you have understood scaffolding feature and i've demonstrated you a very quick simple example i'm sure you can go ahead try this on your own so guys thank thanks once again for watching this video and please do subscribe to channel and like this video thank you
Info
Channel: Digital TECHJOINT
Views: 143
Rating: undefined out of 5
Keywords: asp.net, asp.net core, scaffolding, learn web application, develop web application project, vs 2019, asp.net core scaffolding, entity framework, core entity framework
Id: GGZo853j-k0
Channel Id: undefined
Length: 17min 30sec (1050 seconds)
Published: Fri Apr 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.