나는 User
및 Profile
엔터티와 1-1 관계를 가지고 있습니다.
MVC 코드 첫 번째 - 계단식 삭제 1 : 1 관계
사용자 엔티티 및 구성
public class User
{
public int ID { get; set; }
public virtual Profile Profile { get; set; }
}
public class UserConfig : EntityTypeConfiguration<User>
{
public UserConfig()
{
HasRequired(x => x.Profile).WithRequiredPrincipal(x => x.User);
}
}
프로필 엔티티와 CONFIGS 그러나
public class Profile
{
public int ID { get; set; }
public virtual User User { get; set; }
}
public class ProfileConfig : EntityTypeConfiguration<Profile>
{
public ProfileConfig()
{
HasRequired(x => x.User).WithRequiredDependent(x => x.Profile).Map(x => x.MapKey("UserID")).WillCascadeOnDelete(true);
}
}
내가 아래에이 예외 얻을 사용자 목록 삭제하려고 :
List<User> users = _user.Where(x => m.SelectedUsersID.Contains(x.ID)).ToList();
users.ForEach(x => _user.Remove(x));
A relationship from the 'Profile_User' AssociationSet is in the 'Deleted' state. Given multiplicity constraints, a corresponding 'Profile_User_Source' must also in the 'Deleted' state.
나는, 당신은 사용자를 삭제 :
:'HasRequired (X => x.Profile) .WithRequiredPrincipal (X => x.User) .WillCascadeOnDelete (TRUE);'하지만, 나는 여전히 같은 오류가있다. 어쨌든 나는 대답을 발견하고 위에 쓴, 큰 감사합니다 – mhesabi