开发者

Create multiple tables from 1 class at runtime

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");
     }
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜