c# - Multiple collections of same type in entity framework -


i have these 2 simple classes.

public class person {     public int id { get; set; }     public string name { get; set; }     public group group { get; set; } }  public class group {     public int id {get;set;}     public icollection<person> teachers { get; set; }     public icollection<person> students { get; set; } } 

i ef keep teachers seperated students both jumbled person table no way distinguish between them.

any ideas?

there 2 ways it;

first : use tag or enums in person object

public class person {     public int id { get; set; }     public string name { get; set; }     public group group { get; set; }     public bool isfaculty { get; set; } } 

or

public enum persontype { teacher, student };   public class person {     public int id { get; set; }     public string name { get; set; }     public group group { get; set; }     public persontype proppersontype { get; set; } } 

second : work object oriented inheritance. method has preference because it's easy manage , expand if want expand it.

public class person {     public int id { get; set; }     public string name { get; set; }     public group group { get; set; } }   public class student : person {     public int year { get; set; }     // other student related fiels. }   public class teacher : person {     public list<course> courses { get; set; }     // other teacher related fields } 

your group

public class group {     public int id {get;set;}     public icollection<teacher> teachers { get; set; }     public icollection<student> students { get; set; } } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -