gpt4 book ai didi

c# - 更新 ASP.NET Core Entity Framework 中的实体类

转载 作者:IT王子 更新时间:2023-10-29 04:38:21 26 4
gpt4 key购买 nike

我使用 ASP.NET Core 中的 Entity Framework 从现有数据库创建了模型。

这是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。现在我想更新模型。

找到了一些链接,但这个链接再次创建了整个模型 https://learn.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db

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

最佳答案

一个选项是-

您可以使用带有 -force 标志的 Scaffold-DbContext 命令。这样您就可以强制脚手架覆盖现有的模型文件。

示例命令 -

Scaffold-DbContext "<ConnectionString>" Microsoft.EntityFrameworkCore.SqlServer -t <tablename> -f

根据您的要求替换 ConnectionString 和 TableName。

关于c# - 更新 ASP.NET Core Entity Framework 中的实体类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41233300/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com