如何使用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);
}
}
}
答案 0 :(得分:1)
您已复制/重复使用poco EntityNames。
每个实体都映射到一个表。它不能映射到mutliple表。
什么时候Context.Set<TPoco>()
引用哪个表引用它?
在你的情况下,最后的定义是赢。
你可以