【问题标题】:EF Core Power Tools Reverse engineer create different attributes on model on different SQL serversEF Core Power Tools 逆向工程师在不同 SQL 服务器上的模型上创建不同的属性
【发布时间】: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


【解决方案1】:

正如@Karan 所说,这是因为用于脚手架的用户没有 dbo 作为默认架构。

见https://github.com/dotnet/efcore/blob/master/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs#L174

【讨论】:

  • 你是对的,问题在于,另一个数据库上的用户没有默认的默认方案。那么好问题是为什么会这样 :-) 感谢您的帮助。
猜你喜欢
  • 2018-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-29
  • 2017-04-14
相关资源
最近更新 更多