I have classes something like below. I would like to reuse classes and persist them in different tables by using entity framework code first.
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public bool IsAvailable { get; set; }
public List<Part> Parts { get; set; }
public List<Promotion> Promotions { get; set; }
}
public class Field
{
public int Id { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}
public class Part
{
public int Id { get; set; }
public string Name { get; set; }
public List<Field> Details { get; set; }
}
public class Promotion
{
public int Id { get; set; }
public string Name { get; set; }
public List<Field> Details { get; set; }
}
I want to map my entities such a way that I would get database tables generated like below.
Products: Id, Name, IsAvailable
ProductParts: Id, Name, ProductId
ProductPartDetails: Id, Name, Value, ProductPartId
ProductPromotions: Id, Name, ProductId
ProductPromotionDetails: Id, Name, Value, ProductPromotionId
What I am actually interested in here is I want the Field class reused and gets stored in different tables ProductPartDetails and ProductPromotionDetails as I described above. Is it possible or my approach needs to be changed?