Error after 'update-database' in Entity Framework 6

asp.net asp.net-web-api2 c# entity-framework-6

Accepted Answer

There are several paths of relations that contribute to this issue. If you remove one record, it will ultimately remove records from another table, which will remove records from yet another table, which will remove records from the table you first selected, and so on. The greatest nightmare for a developer, really terrible. Add custom characteristics to your migration, for example, to solve this problem:

CreateTable(
            "dbo.SomeTable",
            c => new
            {
                id = c.Int(nullable: false, identity: true),
                createdon = c.DateTime(),
                createdby = c.String(),
            })
            .PrimaryKey(t => t.id)
            .ForeignKey("dbo.Customers", t => t.Customerid, cascadeDelete: true)
            .ForeignKey("dbo.AnotherTable", t => t.Anotherid, cascadeDelete: false)
            .Index(t => t.Customerid)
            .Index(t => t.Scopeid);

Make thecascadeDelete to false or AutoUpdate to false Identify the impacted tables/(model classes backing) and make the necessary updates to the database.

Your relationship is cyclic, for example: Customer -> Payroll -> Customer -> Salary. Therefore, when you remove a customer, its associated salary record(s) are/are destroyed, along with the associated payroll records. This cycle then loops back to delete related customers, generating havoc. Because of this, Entity Framework and SQL ask the user to disable any impacted or error-causing deletion or update connections.

1
8/30/2017 7:11:07 PM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow