0

我有三个班UserProfileGroupsContacts。我想删除 aGroup而不删除它的Contacts. GroupIDin Contactstable 应设置为删除null时。Group该怎么办?

三类:

[Table("UserProfile")]
public class UserProfile
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }
    public string UserName { get; set; }
    public virtual ICollection<Groups> Groups { get; set; }
    public virtual ICollection<Contacts> Contacts { get; set; }
}

public class Groups
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int GroupID { get; set; }
    [Required]
    public string GroupName { get; set; }
    public string Description { get; set; }
    [ForeignKey("User")]
    public int UserID { get; set; }
    [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
    public DateTime? CreateDate { get; set; }
    [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
    public DateTime? ModifiedDate { get; set; }

    public virtual UserProfile User { get; set; }

    public virtual ICollection<Contacts> Contacts { get; set; }
}

public class Contacts
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int ContactID { get; set; }
    [ForeignKey("Group")]
    public int? GroupID { get; set; }
    [ForeignKey("User")]
    public int UserID { get; set; }
    public Prefix? Prefix { get; set; }
    [Required]
    public string FirstName { get; set; }
    [Required]
    public string LastName { get; set; }
    [Required]
    [DataType(DataType.Date)]
    public DateTime? BirthDate { get; set; }
    [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
    public DateTime? CreateDate { get; set; }
    [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
    public DateTime? ModifiedDate { get; set; }

    public virtual UserProfile User { get; set; }
    public virtual Groups Group { get; set; }
    public virtual ICollection<Groups> Groups { get; set; }
}
4

0 回答 0