dear community of professional developers!
I'm trying to figure out how to make a mapping correctly using Code First.
Assume that there are a few classes. One container-class, one base-class and several descendant classes.
The base-class:
public class Base {
public int Id { get; set; }
}
The descendant classes:
public class FirstDescendant {
public string FirstProperty { get; set; }
}
public class SecondDescendant {
public int SecondProperty { get; set; }
}
public class ThirdDescendant {
public int ThirdProperty { get; set; }
}
The container-class:
public class Container {
public int Id { get; set; }
public ICollection<FirstDescendant> FirstDescendants { get; set; }
public ICollection<SecondDescendant> SecondDescendants { get; set; }
public ICollection<ThirdDescendant> ThirdDescendants { get; set; }
}
By default, after creating the DbContext and running my code I get two tables with the following structure:
The Container table
Id
The Base table
Id
FirstProperty
Container_Id1
SecondProperty
Container_Id2
ThirdProperty
Container_Id3
So I get a table named Base, which contains the idential three fields that have the idential role of the foreign key.
Now the questions:
I do not like that kind of redundancy. How to evaluate this situation professional community, is this normal?
Can I change this? Can I get a more clearn structure of the database?
What is the best way to map this classes?
I have already published a similar question but I still care about this issue.
Thank you for your answers and attention.