In the above command, the first parameter is a connection string which includes three parts: DB Server, database name, and security info. Here, Server=.\SQLExpress; refers to the local SQLEXPRESS database server. Database=CodingvilaDB; specifies the database name "CodingvilaDB" for which we are going to create classes. Trusted_Connection=True; specifies the Windows authentication. It will use Windows credentials to connect to the SQL Server. The second parameter is the provider name. We use the provider for the SQL Server, so it is Microsoft.EntityFrameworkCore.SqlServer. The -OutputDir parameter specifies the directory where we want to generate all the classes which is the Models folder in this case.
The above Scaffold-DbContext command creates entity classes for each table in the CodingvilaDB database and context class (by deriving DbContext) with Fluent API configurations for all the entities in the Models folder.
I hope this helps you.
Thank you.
+1
Sachin SinghRank #66 · 26.2K reputationPosted Jan 9, 2021, 4:56 AM EST
+1
after adding connection string to the web.config file , when you run the migration then EF automatically detects it.
Enable-Migrations
Add-Migrations InitialModel
update-database
These are just the simple steps of code-First workflow.
+1
Jignesh KumarRank #91 · 22.9K reputationPosted Jan 9, 2021, 11:39 PM EST
+1
Hi,
You can do from Package manager console, Please refer
Yogeshkumar HadiyaRank #358 · 7K reputationPosted Jan 9, 2021, 10:13 PM EST
Nikunj SatasiyaRank #302 · 8.3K reputationPosted Jan 9, 2021, 4:38 AM EST
Sachin SinghRank #66 · 26.2K reputationPosted Jan 9, 2021, 4:56 AM EST
Jignesh KumarRank #91 · 22.9K reputationPosted Jan 9, 2021, 11:39 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts