C# EF多模式代码优先
如何使用codefirst方法在EF中创建具有多个模式的表 我有这个上下文,但似乎只有模式。军团被创建了 任何帮助都将不胜感激C# EF多模式代码优先,c#,entity-framework,ef-code-first,C#,Entity Framework,Ef Code First,如何使用codefirst方法在EF中创建具有多个模式的表 我有这个上下文,但似乎只有模式。军团被创建了 任何帮助都将不胜感激 namespace DotA.Server.Context { public class DotAContext : DbContext { public DbSet<EFHero> Hero { get; set; } public DbSet<EFItem> Item { get; set; }
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);
}
}
}
名称空间DotA.Server.Context
{
公共类DotAContext:DbContext
{
公共数据库集英雄{get;set;}
公共数据库集项{get;set;}
公共数据库集技能{get;set;}
公共DbSet Stat{get;set;}
私有模式;
私有静态只读ConcurrentDictionary ModelCache=新ConcurrentDictionary();
公共DotAContext(模式)
:base(“name=DotAConnectionString”)
{
this.schema=schema;
}
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
modelBuilder.Entity().ToTable(“Hero”,Schema.tribul.ToString());
modelBuilder.Entity();
modelBuilder.Entity().ToTable(“Item”,Schema.briath.ToString());
modelBuilder.Entity().ToTable(“Stat”,Schema.briath.ToString());
modelBuilder.Entity().ToTable(“Hero”,Schema.Legion.ToString());
modelBuilder.Entity().ToTable(“Skill”,Schema.Legion.ToString());
modelBuilder.Entity().ToTable(“Item”,Schema.Legion.ToString());
modelBuilder.Entity().ToTable(“Stat”,Schema.Legion.ToString());
基于模型创建(modelBuilder);
}
}
}
您已经复制/重用了poco实体名。
每个实体都映射到一个表。它不能映射到多个表。
当两次声明时,Context.Set()
应该引用哪个表?
在你的例子中,最后一个定义是赢
你可以
不。。它起作用了。。我所做的是多方面的。。谢谢@phil