【发布时间】:2017-04-02 04:11:51
【问题描述】:
这个问题是 4 年前在这里提出的:EF Mapping to prefix all column names within a table 我希望现在有更好的处理方式。
我正在使用 EF6 Fluent API,我将其称为 Code First without Migrations。我的模型有 POCO,并且我的大多数数据库列名称都定义为 [SingularTableName]Field(例如,CustomerAddress db 列映射到 Customers POCO 中的 Address 字段)
表格:
CREATE TABLE dbo.Customers (
-- ID, timestamps, etc.
CustomerName NVARCHAR(50),
CustomerAddress NVARCHAR(50)
-- etc.
);
型号:
public class Customer
{
// id, timestamp, etc
public string Name {get;set;}
public string Address {get;set;}
}
模型构建器:
modelBuilder<Customer>()
.Property(x => x.Name).HasColumnName("CustomerName");
modelBuilder<Customer>()
.Property(x => x.Address).HasColumnName("CustomerAddress");
目标:
我真正想要的是能够为 FluentAPI 说这样的话:
modelBuilder<Customer>().ColumnPrefix("Customer");
// handle only unconventional field names here
// instead of having to map out column names for every column
【问题讨论】:
标签: entity-framework entity-framework-6 ef-fluent-api