In this article i will show you how to connect asp.net core 6 mvc project or application with ms sql server database using entity framework core or EF core and c#. In this i have explained the DB first approach or database first approach or db first approach. I have used scamfold-dbcontext command.
First you need to install below mention nugget packages.
- Microsoft.EntityFrameworkCore.Tools
- Microsoft.EntityFrameworkCore.Design
- Microsoft.EntityFrameworkCore.SqlServer
After this we need to run the below scamfold-dbcontext
context in package manager console. Here the below mention command we will run if we are running
the command first time.
Scaffold-DbContext
"Server=.\SQLEXPRESS;Database=Employee;Trusted_Connection=True;"
Microsoft.EntityFrameworkCore.SqlServer -OutputDir data
In above need to define the connection string and then
provider and then defined the directory where we EF core context and table object
class files will create.
To update the DB context after making change in Database
table. We will run below command.
Scaffold-DbContext
"Server=.\SQLEXPRESS;Database=Employee;Trusted_Connection=True;"
Microsoft.EntityFrameworkCore.SqlServer -OutputDir data –force
In above we have added –force. So by using this we will be
able to update the context file and modified table objects class files.
Related Topics:
- Entity Framework Database First In ASP.NET Core
- Entity Framework Core with Existing Database
- EF Core 6 Database First / DB First (Entity Framework Core
6)
- How do I create a database first in Entity Framework?
- How do I create a DbContext in Entity Framework core
database first?
- EF Core Database-First Tutorial for .NET Core
- Creating a model for an existing database in entity
- EF core database first sql server
- .Net core database first
- Entity framework database first
- ASP.Net Core: Entity Framework Database First Approach
- Database First approach in Entity Framework Core 6
- Database first approach in entity framework core 6
DOWNLOAD
0 comments:
Please let me know your view