我使用的是asp.net wepAPi,我在employee和employeeLoan之间有一个外键列;
public class Employee
{
[Key,Required]
[StringLength(50)]
public String EmpID { get; set; }
}
public class EmployeeLoan
{ [Required]
[Display(Name="Employee")]
public String EmpID { get; set; }
[ForeignKey("EmpID")]
public virtual Employee Employee { get; set; }
}
如何构建C#模型,以便生成具有级联更新的外键约束
ALTER TABLE [dbo].[EmployeeLoans] WITH CHECK ADD CONSTRAINT [FK_dbo.EmployeeLoans_dbo.Employees_EmpID] FOREIGN KEY([EmpID])
REFERENCES [dbo].[Employees] ([EmpID])
ON UPDATE CASCADE -- I want this portion to be added but with this model it s not added
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[EmployeeLoans] CHECK CONSTRAINT [FK_dbo.EmployeeLoans_dbo.Employees_EmpID]
GO
感谢先进!!