Subtitles section Play video
So in this video we will try to understand what exactly is this word called as scaffolding in MVC.
The word is big but the thing what is does is simple and useful. So let us try
to understand it so i want to go to a my visual studio and a let me create a project here
called as scaffolding so there am you can see yhat i am using MVC 5 at this moment
and one of the biggest feature in mvc 5 uniform experience. so for example if you are a old webform developer take this
template than create a project. if you are new guy who believes in mvc than u can take
this or u can take ppi so rest of the services.but at this moment let's take MVC we wil take mvc because
we are doing scaffolding and what i will do is let me say no authentication at this moment that it keep my project simpler
because if i use this one of this authentication it niether create code for window authentication
or form authentication so at this moment to keep simple i will say ok. so let me go ahead
and create a model here so let me first go ahead and create a model so i am create an
add new item now remember so end of the day model is nothing but a very simple csharp
class like a customer class or supplier class so will go here and say a customer at this
moment let say customer.cs so let me go create a couple of properties so i use snippet code
for code generation so i say here string customercode than i say prop again tab tab string customername
so what exactly is scaffolding. Scaffolding is nothing but technique which help you to
generate a CRUD code to keep update,delete your appliaction, so far example here simple
customer class properly over this customer class is valid like to go an create a data
acsess layer and go create a customer table i would like to screen for edit,update,delete
& insert right. so what wecan do go to solution explore and i will go add controller
remember you know whatever will do in MVC at end of the day you need a controller so the first
it come to the controller. The controller it work of object and modelise i would say
and its then ties of the model with the view so right let me go an create an simple controller here
so i wills say add a controller so you can see add a scaffo;d template here. so far example
i do use this template here so this template mvc5 controller with view using entity framework
so this tempich you late what it does it create your read & update and delete code interally
it use a entitiy framework to do the database opeartions that is your CRUD operations right
and it's create view using a razors so let me go use this template here so i say yes i want
to use mvc5 using entity framework and say add so now the next thing what it ask to saying
that ok so basically you want to go and build this code around what like it is customer class it is supplier class what is model
i will say and build this code around it's customer class over here i will say that yes a generate view,script libaries all those i will name in this a controller
as customer controller to that is also fine and i will say that now if you have customer class than
you will have a entity framework add a constext class remember i wil said that this template uses internally so i will say yes i want to add data context class here so i will say this data context class is with the name customer right
so what is data context classdata context class is the bridage which you know which a connect your model
with the data base. so it will have a you know all code which is insert and update and
detail.it is act a dataexcess to think about so you have a model that is your model called
as customer context will talk interally with the data base right so it is entity framework
class actually so fine i have done i will say add now you can see he is giving me errror here saying that your customer does not
not have key defined but remember when we talk about entity framework for entity framework
you need key a unique key so that the code genetated properly so what it will do go and i want to go
dentified the key on customer code so using system .Componenet model. Dataannotations so we want to go and uses atrebulate her called as keys
what i have done put a key over the customer code so say that a now customer code is a unique key over here great let me go and build this is again
and again go generate a scaffold template so again it take a scaffold template generate so go here
and say add a controller so lets add a controller name again i will use this mvc5 controller with views using entity framework and i will say and say generate
the code around customer class here name this context class you know which wii conect
the model and sql serves so i am to go say name as customer contaxt it's more reasonable name not interested
in a layout page or master page at this moment and i say add so i hope this time we should dont have problems
so can see here magic so you can see here that he genaerated much code code over here customer
class it has create it has edit is as delete you know i am not going to other method you know but
overall you can see that he has generated lot of code you know wich will help to create, delete,edit
rights so crud operation and also if you see here yes create a lots of view here if you go and see here
ther is create.cshtml remember cshtml is razor view you can see here there has create a view there is delete view there is detail view etc so what i
will do let me go create a customer entry right
so in order to go and invoke this thing what did you say here customer/create right so i will do controll a file here so remembr you have to give here controller name and then the action
name and remember you shouldn't be put in the word controller here right so will just press enter
so there it is you can see the screen already created i can say here 1001 and shiv
i will just add and create right so there you can see record created at the same time always go and click on edit and and i can edit
the record and i can say shiv 123 and save it remember i defined the key on customer code
right so thats why does not allowing me to change it right you can say
shivprasad koirala and save it greate so you can see that so scaffolding is nothing but the technique it's technique which help you to generate
read,update and delete code also one point you know which come to your mind so where exactly
is the databases created right so if you go to your web.config file right you will find that
there is a database created a local database created you can see i want go and move the tool box here you can see there is a catalog created called as customer
context and with some number over here right so this is a mdf file here so if you go here view
server explorer very quickly you shohuld find this customer context you can see here customer context scaffolding go and make this bigger you can see on lefthand side it
he showingme mdf file and in this in he must be have created a table called as customer right this all done by using a entity framework okk
and this is the the table here these all thing done in entity framework at the backend right so whatever we have added edited and you know it shuld be line in this table here so you know simple word
scaffold is a technique which helps to generate create,read,update and delete opeations but you know
my honest suggestion is not use scaffolding why beacuse you know it generate automited code so
must be that the articulture that code doesn't suit your standard so in case you want show
some quick demo to create some screen do something quickly like a rat think it is fine but if you
are talking about a professional projects and enterperise projects you should avoid it
and specially when you are learning mvc you should avoid it you know because if you go use scaffolding
it generate lots of code and those code you don't understand you not learn mvc so my honest
suggestion is you know you do scaffolding only when you want to show some quick demo if somebody saying
do think quickly you can use scaffolding but else you know on serious project and enterprise projects you should just avoid it
so if you like this video please go and share this video on you
facebook page and second i would like to make small announcment here we have started learn
mvc5 in 2day course which is available in offline format in other words come to our
institutes and learn in offline a new batch fresh batch or small batch so in case if you are interested
you can always call up on this number or send us email over here so you can call up one of this number the cost is reasonable
the machine we will provide food we will provide you are just come with your head sit learn and go so do think about it
it if any issue please do email us on this address thanku you so much.