[英]EF Multiple Schema CodeFirst
如何使用Codefirst方法在EF中創建具有多個架構的表。
我有此上下文,但似乎只創建了Schema.Legion。
任何幫助,將不勝感激。
namespace DotA.Server.Context
{
public class DotAContext : DbContext
{
public DbSet<EFHero> Hero { get; set; }
public DbSet<EFItem> Item { get; set; }
public DbSet<EFSkill> Skill { get; set; }
public DbSet<EFStat> Stat { get; set; }
private Schema schema;
private static readonly ConcurrentDictionary<Tuple<string, string>, DbCompiledModel> ModelCache = new ConcurrentDictionary<Tuple<string, string>, DbCompiledModel>();
public DotAContext(Schema schema)
: base("name=DotAConnectionString")
{
this.schema = schema;
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<EFHero>().ToTable("Hero", Schema.Scourge.ToString());
modelBuilder.Entity<EFSkill>().ToTable("Skill", Schema.Scourge.ToString());
modelBuilder.Entity<EFItem>().ToTable("Item", Schema.Scourge.ToString());
modelBuilder.Entity<EFStat>().ToTable("Stat", Schema.Scourge.ToString());
modelBuilder.Entity<EFHero>().ToTable("Hero", Schema.Legion.ToString());
modelBuilder.Entity<EFSkill>().ToTable("Skill", Schema.Legion.ToString());
modelBuilder.Entity<EFItem>().ToTable("Item", Schema.Legion.ToString());
modelBuilder.Entity<EFStat>().ToTable("Stat", Schema.Legion.ToString());
base.OnModelCreating(modelBuilder);
}
}
}
您已經重復/重用了poco EntityNames。 每個實體都映射到一個表。 它不能映射到多個表。 兩次聲明Context.Set<TPoco>()
應該引用哪個表? 就您而言,最后的定義就是勝利。
你可以
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.