List, virtual and Entity Framework

1

In all examples I have found about entity framework, they always use ICollection for object collections.

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 Can not 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, does the EF make any changes to it?

    
asked by anonymous 26.05.2016 / 17:16

1 answer

6

Entity Framework , ORM used in .NET architecture.

Responding:

1) Yes, you can seamlessly use Concrete Type List it will work just like Interfaces .

Advantage in this regard is that in the constructor I do not need to initialize this List, as is done with the interfaces (

26.05.2016 / 17:48