This question may be simple, but the logic is important and I'm confused about it. In Asp.Net Core 2.1 with Entity Framework Core Code First, I want to learn how to model, so i have simplified the problem. One same navigation property (Photo) in two different entity (Center and Article). Center can has many photos and article can has one photo. A photo can has one post or one center, so can has one MyEntityBase. Example:
public class Photo
{
public int Id { get; set; }
public string Url { get; set; }
//The question/relation problem is here???
//public int CenterId { get; set; }
//public virtual Center Center { get; set; }
//public int ArticleId { get; set; }
//public virtual Article Article{ get; set; }
//public int MyEntityBaseId { get; set; }
//public virtual MyEntityBase ArticleOrPost{ get; set; }
}
public class Article: MyEntityBase
{
[Key]
public int Id { get; set; }
public string Title { get; set; }
//Common Photo property
//One article has one photo
public virtual Photo ArticlePhoto { get; set; }
}
public class Center: MyEntityBase
{
[Key]
public int Id { get; set; }
public string Name{ get; set; }
//Common Photo property
//One center has many photo
public virtual List<Photo> CenterPhotos { get; set; }
}