此代码没有给出任何错误,但除医院数据外,数据未插入数据库
public class HospitalInitializer:DropCreateDatabaseIfModelChanges
{
protected override void Seed(DoctorContext context)
{
var hospitals = new List<Hospital>
{
new Hospital() {Name = "Agha Khan"},
new Hospital() {Name = "liaquat national"},
new Hospital() {Name = "Tabba heart center"}
};
hospitals.ForEach(c => context.Hospitals.Add(c));
context.SaveChanges();
var Doctors = new List<Doctor>
{
new Doctor() {Name = "dr shah", qualification="MBBS", fee= 1000, specialization= "General", Hospital = context.Hospitals.Single(p=>p.Name == "Agha Khan"),
appointments = new List<appointment>{
new appointment { date_appoint= "2013-11-20 " ,
confirm_appoint= "yes",
cancelation_appoint=" Not yet",
}}
},
new Doctor() {Name = "dr ahmed", qualification="MBBS", fee= 1500, specialization= "Derm", Hospital = context.Hospitals.Single(p=>p.Name == "liaquat national"),
appointments = new List<appointment>{
new appointment { date_appoint= "2013-11-20 " ,
confirm_appoint= "yes",
cancelation_appoint=" Not yet",
}}
},
new Doctor() {Name = "dr Faisal", qualification="MBBS MRCOG", fee= 1500, specialization= "Derma", Hospital=context.Hospitals.Single(p=>p.Name == "baqai national") ,
appointments = new List<appointment>{
new appointment { date_appoint="2013-11-20 " ,
confirm_appoint= "yes",
cancelation_appoint=" Not yet",
}}
}
};
Doctors.ForEach(c => context.Doctors.Add(c));
context.SaveChanges();
var facilities = new List<Facility>
{
new Facility() { facilityname = "ECG", fac_type = "CARDIC", Doctors=context.Doctors.Find(1)},
new Facility() { facilityname = "eco", fac_type = "heart", Doctors=context.Doctors.Find(2)},
new Facility() { facilityname = "eco", fac_type = "heart", Doctors=context.Doctors.Find(3)}
}; facilities.ForEach(c =&gt; context.Facilities.Add(c));
context.SaveChanges();
var patients = new List<patient>
{
new patient() { name = "abbass" , type_disease= "brain disorder", pat_history= "2 years", cell_no = 03457889654, phonenumber= 35660453 , Doctors=context.Doctors.Find(1)},
new patient() {name= "amna qasim" ,type_disease =" skin allergy" ,pat_history= "2 years",
cell_no = 03457889654, phonenumber= 35660453 , Doctors=context.Doctors.Find(2)},
new patient() {name= "tooba ahmed" ,type_disease ="heart problem" ,pat_history= "1 years",
cell_no = 03457889654, phonenumber= 35660453 , Doctors=context.Doctors.Find(3)},
};
patients.ForEach(c => context.patients.Add(c));
context.SaveChanges();
var newsletter = new List<Newsletter>
{
new Newsletter () { url="www.news1.com",
description="newsletter of janvary",
UserProfiles= context.UserProfiles.Find(1)
},
new Newsletter () { url="www.newsletter2.com",
description="newsletter of feb",
UserProfiles= context.UserProfiles.Find(2)
},
new Newsletter () { url="www.news1.com",
description="newsletter of march",
UserProfiles= context.UserProfiles.Find(3)
}
};
newsletter.ForEach(c => context.newsletters.Add(c));
context.SaveChanges();
var roles = new List<Role>
{
new Role() {
roletype="doctor",
roledescription =" skin specialits",
UserProfiles = new List<UserProfile>{
new UserProfile { username= "shah1",
email="shah.ali@gmail.com",
password="ali12",
phonenumber= 033345678,
city= "karachi",
country= "pakistan",
postalcode= 34567,
address= "gulshan e iqbal town",
}
}
},
new Role() {
roletype="doctor",
roledescription =" skin specialits",
UserProfiles = new List<UserProfile>{
new UserProfile { username= "shah1",
email="shah.ali@gmail.com",
password="ali12",
phonenumber= 033345678,
city= "karachi",
country= "pakistan",
postalcode= 34567,
address= "gulshan e iqbal town",
}
}
},
new Role() {
roletype="patient",
roledescription =" patient of skin diseases",
UserProfiles = new List<UserProfile>{
new UserProfile { username= "gm1",
email="tayaba@gmail.com",
password="ali12",
phonenumber= 0334567892,
city= "karachi",
country= "pakistan",
postalcode= 34567,
address= "f.b area",
}
}
}
};
roles.ForEach(c => context.Roles.Add(c));
context.SaveChanges();
var ambulance = new List<Ambulance>
{
new Ambulance()
{
amb_no = "2367",
//Doctors = context.Doctors.Find(1),
Locations = new List<Location>{
new Location { location= "gulshan e iqbal",
Facilities= context.Facilities.Find(1)
}
}},
new Ambulance()
{
amb_no =" 12457",
//Doctors = context.Doctors.Find(1),
Locations = new List<Location>{
new Location { location= "defence",
Facilities= context.Facilities.Find(2)
}
}
},
new Ambulance()
{
amb_no = "56787",
//Doctors = context.Doctors.Find(1),
Locations = new List<Location>{
new Location { location= "aisha manzil",
Facilities= context.Facilities.Find(3)
}
}
},
};
ambulance.ForEach(c => context.Ambulances.Add(c));
context.SaveChanges();
}
}
}
请帮我查一下为什么这段代码没有插入数据库