更新ASP.NET Core实体框架中的实体类

问题描述:

我已经使用ASP.NET Core中的实体框架从现有数据库中创建了模型.

I have created the model from existing database using Entity Framework in ASP.NET Core.

这是Market表的模型

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; }
}

但是,我已将数据库中的MarketId数据类型更改为int.现在我要更新模型.

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

如何在不创建新模型且不使用appsettings.json中的连接字符串的情况下更新模型?

How can I update the model without the creating new model and using the connection string in appsettings.json?

要更新整个dbcontext,请使用以下命令.链接以获取更多详细信息

To Update entire dbcontext use the below command. link for more details

数据库的第一个脚手架-DbContext

Scaffold-DbContext -Connection "Server=(local);Database=DefenderRRCart;Integrated Security=True;Trusted_Connection=True;" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir RRStoreContext.Models -context RRStoreContext -Project RR.DataAccess -force

要从Azure连接和本地连接更新

To update from Azure Connection and local Connection

Scaffold-DbContext "Server=<Server Name>,1433;Initial Catalog=<Database Name>;Persist Security Info=False;User ID=<user id>;Password=<password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Entity -context <Context Name> -Project <project Name> -force

要创建新的上下文

Scaffold-DbContext "Server=<Server Name>,1433;Initial Catalog=<Database Name>;Persist Security Info=False;
        User ID=<User Id>;Password=<Password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection
        Timeout=30;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir <Dir Name>