I use Entity Code first for my project. Basically I have 3 class Users
,Branchs
and UsersBranchs
.
Users
contains UserID
, Name
,...
Branchs
contains BranchID
, Location
, ... and UserID which is refer to creator of branch
and UsersBranchs
just have have two column BranchID and UserID which is define which user is in which branch
the problem is I get this error:
'FK_dbo.UsersBranchs_dbo.Users_UsersID' on table 'UsersBranchs' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Can you help me please?
Update
It's UsersBranchs Class
[ForeignKey("UserID")]
public CoreUsers User { get; set; }
public Guid UsersID { get; set; }
[ForeignKey("BranchID")]
public Branchs Branch { get; set; }
public Guid BranchID { get; set; }
And also add this line to DbContext class to use both UserID and BranchID as key
modelBuilder.Entity<UsersBranchs>().HasKey(x => new { x.UserID, x.BranchID });
Branchs Class is
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public Guid ID { get; set; }
[ForeignKey("UserID")]
public CoreUsers User { get; set; }
public Guid UserID { get; set; }
public .....
Users Class is
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public Guid ID { get; set; }
public .....