1
In all the examples I have found about Entity framework, always use ICollection
for collections of objects.
public partial class Standard
{
public Standard()
{
this.Students = new HashSet<Student>();
this.Teachers = new HashSet<Teacher>();
}
public int StandardId { get; set; }
public string StandardName { get; set; }
public string Description { get; set; }
public virtual ICollection<Student> Students { get; set; }
public virtual ICollection<Teacher> Teachers { get; set; }
}
public partial class Teacher
{
public Teacher()
{
this.Courses = new HashSet<Course>();
}
public int TeacherId { get; set; }
public string TeacherName { get; set; }
public Nullable<int> StandardId { get; set; }
public Nullable<int> TeacherType { get; set; }
public virtual ICollection<Course> Courses { get; set; }
public virtual Standard Standard { get; set; }
}
Questions:
1 Cannot work directly with the concrete type, such as List?
public partial class Standard
{
public int StandardId { get; set; }
public string StandardName { get; set; }
public string Description { get; set; }
public virtual List<Student> Students { get; set; }
public virtual List<Teacher> Teachers { get; set; }
}
2 I also read that EF does not work with collections of primitive types. What to do in this case?
3 Because the property needs to be virtual, the EF does some modification in it?
What do you mean primitive types? You can quote the source?
– Maniero
I believe he wants to record a string array in the database if I’m not mistaken in Entity core 1 are implementing
– user46523