【发布时间】:2017-08-30 18:51:38
【问题描述】:
我正在使用 Entity Framework 6 项目开发 WEB API 2,更新数据库后出现问题。
错误:
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 模型类.. 包含
modelBuilder的那个 -
您需要指定删除费率时用户应该发生的情况。如果你有用户参考费率,和费率参考用户,级联删除会导致问题。
标签: c# asp.net entity-framework-6 asp.net-web-api2