Jeroen
Jeroen

Reputation: 4023

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 ItemA and table ItemB. Can this be done at runtime?

Upvotes: 0

Views: 342

Answers (1)

Yury Tarabanko
Yury Tarabanko

Reputation: 45106

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

Upvotes: 1

Related Questions