I am using EF to scaffold controllers and views for a student class I defined. The strange thing is, that when I use the scaffolded 'create' method to add a Student or try to load localhost/Student, I get an error notice:
SqlException: Invalid column name 'StudentId1'. Microsoft.Data.SqlClient.SqlCommand+<>c.b__164_0(Task result)
DbUpdateException: An error occurred while updating the entries. See the inner exception for details. Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
In my student class, I do not define the column name as StudentId1, but as studentID. Does anyone know where this 1 gets concatenated?
This is my code for Student.cs
public class Student
{
[Key]
public Guid StudentId { get; set; }
[Required]
public int Studentnummer { get; set; }
[Range(1, 100, ErrorMessage = "U bent te oud of nog niet oud genoeg om student te zijn. ")]
public int Leeftijd { get; set; }
public string Voornaam { get; set; }
[MinLength(2)]
public string Achternaam { get; set; }
[DataType(DataType.EmailAddress, ErrorMessage = "Voer een geldig emailadres in.")]
public string Email { get; set; }
[DisplayName("Bevriende studenten")]
public List<Student> Vrienden { get; set; }
[DisplayName("Behaalde cijfers")]
public List<Grade> Cijferlijst { get; set; }
public Student() {
}
public Student(int nr) {
Email = emailGen(nr);
Studentnummer = nr;
}
public Student(int studentnummer, string voornaam)
{
this.Studentnummer = studentnummer;
Voornaam = voornaam;
Email = emailGen(studentnummer);
}
public Student(int studentnummer, string voornaam, string mailie)
{
this. Studentnummer = studentnummer;
Voornaam = voornaam;
Email = mailie;
}
internal string emailGen(int studentnummer)
{
string mail;
mail = studentnummer + "@student.hhs.nl";
return mail;
}
}