The Database First Approach in Entity Framework Core | | Asp.Net MVC Core | by Mr. Sudhakar Sharma

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi in this session we are going to discuss about the database first approach in entity framework core so in ME seek or how to handle database first approach already in previous session we discussed about the code first approach now in database first approach a simple technique if you have an existing database then you can generate all domain-specific classes according to the database and tables so if you are a me see poor application how to communicate with database usually you need to write all the the wine specific data logic now what entity framework core helps you is it will generate database related classes which are required to communicate with the database so you do not need to design any model classes whatever the classes required to communicate with database all those classes are generated by entity framework let's see how it can happen so we will create a new project asp.net core web application and I will name it as entity DB faster in this we will select an application with MVC and let us create an MVC core application in this NBC core application you need to install the library for communicating with the tentative databases we need to right-click and go to you get packages as we already learnt we need two packages one is Microsoft entity framework SQL Server Microsoft entity framework or SQL Server and the three version and install so we are installing entity framework or for communicating with sequel server that is one library we need to install this library and another library we need is the entity framework core tools which is responsible for connecting with the database through commands means configuring updating the database to commands so once entity framework for SQL Server package is installed I am selecting entity framework related all dependencies once these dependencies are ready I will install another entity framework for tools so these tools will give me access to the commands that I need so these tools also 3.0 and install so these tools will give me access to the commands which are used for updating with the database so what we are going to do here is a sponsor the packages are ready in my models you can see initially there is some error view model some models are empty so we are going to the database we just created a database in the earlier session that is the MVC code DB this a-kor DB is having tables that is categories and products now we have an existing database in tables to communicate with these existing database in tables we need some divine classes business specific logic what entity framework can do it can generate all the logic that you need to communicate with these tables let us see how the logic is generated very simple you need to just go to tools in that nougat package manager' in that package manager console in the package manager console we need to execute a command the command is a scaffold scaffold DB context in scaffold a bit context we need to define the connection string so let's add a verbatim character and define the connection string and use a single code for the connection string so connection string is data source data source is a local and initial catalog initial catalog is cody be the database and user ID password so 1 through P in the package manager we defined scaffold dbcontext scaffolding is a technique that allows to generate all the classes that are required specific requirements to communicate with any database so scaffold dbcontext is going to generate all the classes according to the context defined so we just need to specify the connection string which already we done the connection string is defined and we need to configure the provider name the provider name is Microsoft Microsoft dot entity framework framework core entity framework core dot sequel server that is the provider and where these files need to be generated domain classes need to be generated you have to define that by using - output dir output dr indicates into which folder these files need to be generated it should be generated into the folder models so finally the command scaffold dbcontext it will connect with the database defined in specific location using this provider and it will generate all the classes that are required to communicate with the database and store them models let us execute this command in order to run this command you need the SQL server tools to be installed already we installed entity framework SQL Server - through that we can access now you can see the scaffold finish let's observe our project and see here in the models you can observe there is TBL categories which is mapping to the categories table with category ID and category name and we have TBL products which is mapping to the product ID and category ID which is a foreign key and we have a context context is using DB context and it is using the for dbcontext options and it is using the connection string with the two DB sets one is TBL categories another one TBL products so whatever the logic that you need to communicate with the database all the logic is generated by adding a simple command scaffold DB context so this is database first approach so you have database then entity framework will generate all the classes that are required to communicate with the database in our next session we are going to discuss how to handle the curve operations using entity framework core thank you [Music]
Info
Channel: Naresh i Technologies
Views: 43,378
Rating: undefined out of 5
Keywords: The Database First Approach in Entity Framework Core, entity framework core, asp.net core, entity framework, MVC Core, sudhakar Sharma, Naresh IT, asp.net mvc tutorial
Id: 2m_3SHGy-Rs
Channel Id: undefined
Length: 9min 21sec (561 seconds)
Published: Thu Jan 02 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.