I tried to make entity framework latest version (6.1.2) work with Sqlite but i failed, It worked after I downgraded to version 6.0.1 but now I am having a problem with the one to many realtionship mapping
here is the parent and the child class i use:
public class Teacher
{
public Teacher()
{
Absences = new HashSet<Absence>();
Students = new HashSet<Student>();
}
public long TeacherId { get; set; }
[Required]
[StringLength(255)]
public string FirstName { get; set; }
//other properties
public virtual TeacherDetail TeacherDetail { get; set; }
}
public class TeacherDetail
{
public TeacherDetail()
{
Certifications = new HashSet<Certification>();
Teachers = new HashSet<Teacher>();
}
public long TeacherDetailId { get; set; }
public long TeacherId { get; set; }
[StringLength(250)]
public string Status { get; set; }
//other properties
public virtual ICollection<Teacher> Teachers { get; set; }
}
my DbContext class
public class DZSchoolEntities : DbContext
{
public DZSchoolEntities()
: base("name=DZSchoolDbEntities")
{
}
public virtual DbSet<Absence> Absences { get; set; }
public virtual DbSet<Certification> Certifications { get; set; }
public virtual DbSet<Class> Classes { get; set; }
public virtual DbSet<SchoolDetail> SchoolDetails { get; set;}
public virtual DbSet<SchoolMember> SchoolMembers { get; set; }
public virtual DbSet<Student> Students { get; set; }
public virtual DbSet<TeacherDetail> TeacherDetails { get; set; }
public virtual DbSet<Teacher> Teachers { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<TeacherDetail>()
.HasMany<Teacher>(s => s.Teachers)
.WithRequired(s => s.TeacherDetail)
.HasForeignKey(s => s.TeacherDetailId);
}
}
in my window loaded event i put this to check:
void MainView_Loaded(object sender, RoutedEventArgs e)
{
var person= new Repo().GetTeachers().Where(m=>m.LastName=="mary").First();
var teachers = new Repo().GetTeachers(); //it get me the right person
var detail = person.TeacherDetail; //but it crashes here >_<
}
I can see the correct attributes of the person object by debuging so everything is working fine with the connection, but I can't navigation through propeties tp obtain the teacher details!
Exception:
***An unhandled exception of type 'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.dll **
Inner Exception:
{"SQL logic error or missing database\r\nno such column: Extent1.TeacherId"}
any suggestions please.
Aucun commentaire:
Enregistrer un commentaire