【发布时间】:2021-03-09 15:00:59
【问题描述】:
考虑以下类:
public class Kid
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Date Time BirthDate { get; set; }
public ProfilePhoto CurrentProfilePhoto { get; set; }
public virtual ICollection<ProfilePhoto> ProfilePhotos { get; set; }
}
public class ProfilePhoto
{
public int Id { get; set; }
public byte[] PhotoData { get; set; }
public DateTime DateTaken { get; set; }
public DateTime DateUploaded { get; set; }
public int KidID { get; set; }
public Kid Kid { get; set; }
}
每个孩子实体都有多张个人资料照片,但它可能有也可能没有一张当前的个人资料照片。 另一方面,每个 ProfilePhoto 都与一个孩子相关,并且该孩子的一张 ProfilePhoto 可以是当前的个人资料照片。 如何在 EntityFramework 6.4 中使用 DataAnnotations 或 FluentAPI(如果可能,我更喜欢使用 DataAnnotations)来表示这些关系。
【问题讨论】:
标签: c# sql-server entity-framework ef-code-first data-annotations