1:
newStudent
is a
List<Student>
but
System.Data.Entity.DbSet.Add(..)
(which you're calling with
repository.Students.Add(newStudent)
) takes a single Student, not a List. To add a List of Students, call AddRange instead of Add.
When you fix that, the next problem will be that
y
is of Type
Student
but AddRange will return an
IEnumerable<Student>
. Also your initialization
var y = new Student();
at the top is superfluous (because you never use that single Student instance), aside from not working because of error 3. Remove that line at the top and write instead:
IEnumerable<Student> y = _repository.Students.AddRange(newStudent);
edit after comments: As you're working with EF4, there's no AddRange(..) method. The workaround would be:
foreach(Student student in newStudent)
{
_repository.Students.Add(student);
}
2: Error 2 should vanish when you fix error 1.
3:
Student
doesn't have a parameterless constructor. So you can't create an instance of Student like this:
var xyz = new Student();
var xyz = new Student() { Name = name, Password = pwd, };
Look at the definition of the Student class and look there for the signature of the public constructor(s). There might be a constructor like Student(string name) or maybe all of the fields that you initialize in the ww.Select.. are required. So you have to write them like this:
var xyz = new Student(name, pwd, );