I have created the model from existing database using Entity Framework in ASP.NET Core.
Here is the model of the Market
table
public partial class Market { public Guid MarketId { get; set; } public string City { get; set; } public string CityF { get; set; } public string Name { get; set; } public string NameF { get; set; } public int SortOrder { get; set; } public bool IsActive { get; set; } }
However, I have change the MarketId
datatype to int
in the database. Now I want to update the model.
Found some link but this link create the entire model again https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db
How can I update the model without the creating new model and using the connection string in appsettings.json
?
Updating the Model If you need to re-scaffold the model after database schema changes have been made, you can do so by specifying the -f or --force option e.g.: dotnet ef dbcontext scaffold "Server=. \;Database=AdventureWorksLT2012;Trusted_Connection=True;" Microsoft. EntityFrameworkCore.
To update this entity we need to attach the Department to the context and inform it to mark its status as Modified . Now if we call the SaveChanges method, the context will send an update query to the database.
Right-click anywhere on the design surface, and select Update Model from Database. In the Update Wizard, select the Refresh tab and then select Tables > dbo > Student. Click Finish.
One option is-
You can use Scaffold-DbContext
command with -force
flag. This way you can force scaffolding to overwrite existing model files.
sample command -
Scaffold-DbContext "<ConnectionString>" Microsoft.EntityFrameworkCore.SqlServer -t <tablename> -f
Replace ConnectionString & TableName as per your requirements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With