[英]EF Multiple Schema CodeFirst
How to create tables with multiple schemas in EF with codefirst approach. 如何使用Codefirst方法在EF中创建具有多个架构的表。
i have this Context but it seems only the Schema.Legion is created. 我有此上下文,但似乎只创建了Schema.Legion。
any help would be appreciated. 任何帮助,将不胜感激。
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);
}
}
}
You have duplicated/reused the poco EntityNames. 您已经重复/重用了poco EntityNames。 Each entity is mapped to a table.
每个实体都映射到一个表。 It cant be mapped to mutliple tables.
它不能映射到多个表。 Which table should
Context.Set<TPoco>()
refer to when it is declared twice? 两次声明
Context.Set<TPoco>()
应该引用哪个表? In your case, The last definition is winning. 就您而言,最后的定义就是胜利。
You could 你可以
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.