我有三个班UserProfile
,Groups
和Contacts
。我想删除 aGroup
而不删除它的Contacts
. GroupID
in Contacts
table 应设置为删除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; }
}