Is it possible to have a class X and create multiple tables from it using the Entity Framework 4, code first, during runtime?
For example class Item. I want to create table 开发者_StackOverflowItemA and table ItemB. Can this be done at runtime?
Well, actually you can create multiple tables from one EntityConfiguration
.
But why would you do that?
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
}
public class ItemConfig : EntityConfiguration<Item>
{
public ItemConfig()
{
Property(it => it.Id).IsIdentity();
Property(it => it.Name).IsUnicode().IsRequired().HasMaxLength(100);
MapSingleType(c => new { c.Id, c.Name }).ToTable("dbo.ItemA");
MapSingleType(c => new { c.Id, c.Name }).ToTable("dbo.ItemB");
}
}
精彩评论