Friday, 9 September 2022

Asp.net Core 6 MVC Connect to MS SQL Database EF Core Using C# | Asp.Net Core EF Database First

9/09/2022 - By Pranav Singh 0


 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.

  1.          Microsoft.EntityFrameworkCore.Tools
  2.          Microsoft.EntityFrameworkCore.Design
  3.          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


About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top