【发布时间】:2018-01-24 15:22:18
【问题描述】:
使用 EF 代码 首先,我想为表指定架构 (Data),但让 EF 使用其默认约定来命名表。
我正在使用DataAnnotations.Schema TableAnnotations 来设置架构。
[Table("Customers", Schema = "Data")]
public class Customer
{
public int Id{ get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
但这需要我手动设置Name,而我希望EF 使用它的约定来命名表。
我尝试将Name 设置为空字符串。
[Table("", Schema = "Data")]
这会引发以下 - 非常合理的预期 - 错误:
参数“名称”不能为空、空或仅包含空格。
在指定架构时,有什么方法可以让 EF 默认使用其表名约定?
【问题讨论】:
-
modelBuilder.HasDefaultSchema("Data");
标签: c# entity-framework ef-code-first