[英]Update-database problem in asp.net MVC application
当我在包管理器控制台中更新数据库时出现此错误
在表 'Appointments' 上引入 FOREIGN KEY 约束 'FK_dbo.Appointments_dbo.Users_AppointmentManagerId' 可能会导致循环或多个级联路径。 指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。 无法创建约束或索引。 请参阅以前的错误。
我的课程
[Table("Appointments")]
public class Appointment
{
#region property
[Key]
public int Id { get; set; }
[Required]
[MaxLength(200)]
public string Subject { get; set; }
[Required]
[MaxLength(500)]
public string Description { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy hh:mm tt")]
public DateTime StarTime { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy hh:mm tt")]
public DateTime EndTime { get; set; }
public String Location { get; set; }
#endregion
#region relationship
[ForeignKey("AppointmentCustomer")]
public int AppointmentCustomerId { get; set; }
[ForeignKey("AppointmentManager")]
public int AppointmentManagerId { get; set; }
public virtual Users AppointmentCustomer { get; set; }
public virtual Users AppointmentManager { get; set; }
#endregion
}
[Table("Users")]
public class Users
{
#region property
[Key]
public int Id { get; set; }
[Required]
public string IDUser { get; set; }
[Required]
public string Email { get; set; }
#endregion
#region relationship
[InverseProperty("TicketDeveloper")]
public virtual ICollection<Ticket> TicketDevelopers { get; set; }
[InverseProperty("TicketTester")]
public virtual ICollection<Ticket> TicketTesters { get; set; }
[InverseProperty("ProjectCustomer")]
public virtual ICollection<Project> ProjectCustomers { get; set; }
[InverseProperty("ProjectManager")]
public virtual ICollection<Project> ProjectManagers { get; set; }
[InverseProperty("NoteTester")]
public virtual ICollection<Note> NoteTesters { get; set; }
[InverseProperty("CaseCustomer")]
public virtual ICollection<Case> CaseCustomers { get; set; }
[InverseProperty("AppointmentCustomer")]
public virtual ICollection<Appointment> AppointmentCustomers { get; set; }
[InverseProperty("AppointmentManager")]
public virtual ICollection<Appointment> AppointmentManagers { get; set; }
#endregion
}
好的我解决了make int的问题? 在外键
[ForeignKey("AppointmentCustomer")]
public int? AppointmentCustomerId { get; set; }
[ForeignKey("AppointmentManager")]
public int? AppointmentManagerId { get; set; }
public virtual Users AppointmentCustomer { get; set; }
public virtual Users AppointmentManager { get; set; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.