In today's article I will show a simple tutorial with and an example how you can update Entity Framework table object in an existing object. Here we will see if we are making any change in existing table object in SQL server and update ad a new table in existing SQL server database, on that case how we can update it.
So here is the article where I show how you can connect to SQL server in you new asp.net core mvc application:
- Asp.Net Core MVC: Entity Framework
- How to Connect SQLite Database In .Net Core Using Entity Framework, C#
- What Is EF Core Database First Approach in Asp.Net Core MVC
So, for this article first we will create asp.net core mvc application. Here I am using asp.net core 8 mvc using c#.net. After creating the application, we will create a database with few tables.
Here to connect to SQL server database from Asp.net core mvc application, we will use Scaffold command. Please check the detail of Scaffold command.
Scaffold command syntax for first execution Scaffold-DbContext "Server=<MS SQL Server Name>;Database=<Database name>;Trusted_Connection=True;TrustServerCertificate=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir data
Above syntax describe the complete command detail which we cna execute. Here we are having following items.
Server: <MS SQL Server Name>;
Database: <Database name>;
Trusted_Connection: True;
TrustServerCertificate:True;
The above command is for running the command first time for the application, now to update on second time when we are running, we need to add -force at the end of the Scaffold command. Please check the modified command.
Scaffold command syntax for update Scaffold-DbContext "Server=<MS SQL Server Name>;Database=<Database name>;Trusted_Connection=True;TrustServerCertificate=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir data -force
Now to update the changes in DB we need to run the above (by making change as per your server derail) command from Package manager console.
Now let's check detail of Project detail.
Now at SQL server side we will create a new table and update project table.






