我正在使用Entity Framework 6項目開發WEB API 2,並且在更新數據庫後出現問題。實體框架中的'update-database'後出錯6
錯誤:
Introducing FOREIGN KEY constraint 'FK_dbo.Rates_dbo.Users_Id_User' on table 'Rates' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint or index. See previous errors.
這是我率等級:
public class Rate
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id_Rate { get; set; }
public int Id_User { get; set; }
public int Id_Recipe { get; set; }
public int Value_Rate { get; set; } //1-5
public virtual User User { get; set; }
public virtual Recipe Recipe { get; set; }
}
和我的用戶等級:
public class User
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id_User { get; set; }
public int Id_List_Products { get; set; }
public int Id_List_Black_Products { get; set; }
public string Login { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public Boolean Social_Account { get; set; } // 1 - social account, 0 - normal account
public string URL_Avatar { get; set; } //URL of avatar thumbnail
public virtual List_Products List_Products { get; set; }
public virtual List_Black_Products List_Black_Products { get; set; }
}
我不知道在哪裏的問題。 任何提示?
安置自己的ConnectionString Model類..一個包含'modelBuilder' –
您需要指定應該發生什麼給用戶刪除費率。如果您有用戶參考速率和速率參考用戶,級聯刪除會導致問題。 –
[實體框架:如何解決「FOREIGN KEY約束可能導致循環或多個級聯路徑」?](https://stackoverflow.com/questions/14489676/entity-framework-how-to-solve-foreign-鍵約束-MAY-原因週期 - 或多) –