bai*_*rog 79 c# entity-framework code-first ef-code-first
我有一个实体,我将配置实体框架将其映射到具有不同名称的数据库表.
我可以使用Code First DataAnnotations(DataAnnotations.Schema.TableAttribute)轻松完成此操作.
但由于现在的限制,我必须使用Code First Fluent API(我的域对象将由外部客户端使用,因此它们不应该是特定于技术的 - 例如,对DataAnnotations有任何引用)
我在MSDN上搜索但没有发现任何内容.那有可能吗?怎么样?
谢谢.
Ass*_* S. 205
您还可以使用表注释:
[Table("InternalBlogs")]
public class Blog
Run Code Online (Sandbox Code Playgroud)
请参阅: 代码优先数据注释
小智 83
你将使用这个.ToTable()
方法:
modelBuilder.Entity<Department>().ToTable("t_Department");
Run Code Online (Sandbox Code Playgroud)
来源: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);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
72863 次 |
最近记录: |