1
resposta

Como fazer relacionamento, cascade = false?

Como gerar no migration um relacionamento com cascade = false?

.ForeignKey("dbo.Cidades", t => t.CidadeId, cascadeDelete: true)

1 resposta

Olá, Rodrigo

Você pode tentar editar manualmente uma migration preexistente, usando o método AddForeignKey, como no exemplo abaixo:

public partial class AddMyEntityMyOtherEntity2: DbMigration
{
    public override void Up()
    {
        AlterColumn("dbo.MyEntity", "MyOtherEntityId", c => c.Int(nullable: false));
        CreateIndex("dbo.MyEntity", "MyOtherEntityId");
        AddForeignKey("dbo.MyEntity", "MyOtherEntityId", "dbo.MyOtherEntity", "Id");
    }
    public override void Down()
    {
        DropForeignKey("dbo.MyEntity", "MyOtherEntityId", "dbo.MyOtherEntity");
        DropIndex("dbo.MyEntity", new[] { "MyOtherEntityId" });
        AlterColumn("dbo.MyEntity", "MyOtherEntityId", c => c.Int());
    }
}

fonte: https://stackoverflow.com/a/22714918/1123307

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software