The last weeks I have been working on the development of a database based on Entity Framework 6 (Code-First) on c# using Visual Studio 2015.
I'm currently working on all the options that inheritance offers to work with. At this point and following the standards of a database I should implement multiple inheritance with Primary Key. What this means? This means that I should implement a class that inherits from another class and have his own PK for identify him different from the parent class. At this point I could implement it with TPC, making the parent class abstract and not defining any PK on the parent. This is a sample of the code at this point (this works and I have tested it)
public abstract class Person
{
public string Name { get; set; }
public string LastName { get; set; }
}
[Table("Students")]
public class Student : Person
{
[Key]public int Id_student { get; set; }
public string code_s { get; set; }
public virtual ICollection<Course> courses { get; set; }
}
Then the standard I should follow to build my database requires me to implement another inheritance taking Student as the Parent and creating another class that inherits from Student. The first and stupid idea I had was to make it as simple as write
ChildOfChild : Student
But obviously it didn't work.
Then it come to my mind the possibility of make Student class Abstract, but when I declared the Student class Abstract it didn't let me instantiate it and seed the table. I'm not sure if there is any other way to do this, using abstract class or any other method that could be useful to develop this. If you didn't understand the problem I'm trying to solve this is the sample of code that I would like to have and works.
public abstract class Person
{
public string Name { get; set; }
public string LastName { get; set; }
}
[Table("Students")]
public class Student : Person
{
[Key]public int Id_student { get; set; }
public string code_s { get; set; }
public virtual ICollection<Course> courses { get; set; }
}
[Table("ExchangeStudent")]
public class ExchangeStudent : Student
{
[Key]public int Id_exchange { get; set; }
public string HomeUniversity {get; set;}
}