您好我正在尝试在多上下文项目中启用迁移。我收到这个错误:
在模型生成期间检测到一个或多个验证错误: Mellon.Pricing.RiskControl.Migrations.RetornoValidacao :: EntityType' RetornoValidacao'没有定义键。定义此EntityType的密钥。
事情是在上下文中没有这样的DBSet。
代码如下:
public partial class RiskControlContext : DbContext
{
public RiskControlContext()
: base("RiskControlContext")
{
}
#region Repositorios
IDbSet<DeParaCurvas> _deParaCurvas;
public IDbSet<DeParaCurvas> DeParaCurvas
{
get { return _deParaCurvas ?? (_deParaCurvas = base.Set<DeParaCurvas>()); }
}
IDbSet<DeParaPrecos> _deParaPrecos;
public IDbSet<DeParaPrecos> DeParaPrecos
{
get { return _deParaPrecos ?? (_deParaPrecos = base.Set<DeParaPrecos>()); }
}
IDbSet<PrecoRiskControl> _precoRiskControl;
public IDbSet<PrecoRiskControl> PrecoRiskControl
{
get { return _precoRiskControl ?? (_precoRiskControl = base.Set<PrecoRiskControl>()); }
}
IDbSet<VerticeRiskControl> _verticeRiskControl;
public IDbSet<VerticeRiskControl> VerticeRiskControl
{
get { return _verticeRiskControl ?? (_verticeRiskControl = base.Set<VerticeRiskControl>()); }
}
#endregion
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//Remover as conventions que não são usadas
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
//Adiciona a configuração das entidades de maneira estruturada usando as classes 'TypeConfiguration' em Mapping
modelBuilder.Configurations.Add(new DeParaPrecosConfiguration());
modelBuilder.Configurations.Add(new DeParaCurvasConfiguration());
modelBuilder.Configurations.Add(new PrecoRiskControlConfiguration());
modelBuilder.Configurations.Add(new VerticeRiskControlConfiguration());
}
}
答案 0 :(得分:0)
延迟加载引用实体“DeParaPreco”中的另一个项目是一个问题所以我通过添加
来解决this.Ignore(e =&gt; e.Ativo);
EntityTypeConfiguration 中的