![](/img/trans.png)
[英]how can i change table name by fluent API of entity framework code first in c#?
[英]How to specify table name with Entity Framework Code First Fluent API
我有一个实体,我要配置实体框架以将其映射到具有不同名称的数据库表。
我可以使用Code First DataAnnotations ( DataAnnotations.Schema.TableAttribute ) 轻松做到这一点。
但是由于现在的限制,我必须使用Code First Fluent API (我的域对象将由外部客户端使用,因此它们不应该是特定于技术的 - 例如有任何对 DataAnnotations 的引用)
我在 MSDN 上搜索过,但一无所获。 那么有可能吗?
谢谢。
您将使用.ToTable()
方法:
modelBuilder.Entity<Department>().ToTable("t_Department");
来源:MSDN: http : //msdn.microsoft.com/en-us/data/jj591617.aspx
使用 ToTable 方法:
public class MyEntityMap : EntityTypeConfiguration<MyEntity>
{
public const string TableName = "MyEntity";
public MyEntityMap()
{
ToTable(TableName);
Property(t => t.Id);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.