【发布时间】:2020-11-30 08:16:50
【问题描述】:
我正在使用 EF Core Power Tools 通过在 Visual Studio .Net 中选择 EF Core Power Tools -> Reverse Enegineer 来生成我的模型。
我仍在使用 EF Core 2.x,因此我从您可以选择使用 EF Core 3.x 的第一个对话框中删除了复选标记。
在最后一个选项对话框中我选择:
- 使用 DataAnnotation 属性配置模型。
- 使用 Handlebars 模板 (C#) 自定义代码。
我正在为我的数据库使用 SQL Server。
我的问题是当我在本地数据库上运行工具时生成的模型与另一台服务器上的数据库版本不同。
不同之处在于生成的 POCO 类。 在我的本地数据库上,生成了以下类:
public partial class ExampleTable
{
[Key]
public byte Id { get; set; }
public string Tekst { get; set; }
}
当我针对另一个数据库运行该工具时,代码如下所示:
[Table("ExampleTable", Schema = "dbo")]
public partial class ExampleTable
{
[Key]
public byte Id { get; set; }
public string Tekst { get; set; }
}
为什么该工具在一个数据库的 dbo 表上生成具有属性而在另一个数据库上没有属性的模型?
【问题讨论】:
-
我猜
another database可能有default schema而不是dbo用于您在connectionstring中使用的用户。 -
你是对的,问题在于,另一个数据库上的用户没有默认的默认方案。那么好问题是为什么会这样 :-) 感谢您的帮助。
标签: c# entity-framework-core ef-power-tools