谁能告诉我如何插入数据
Table Student has columns {stuId Name Age}
Table School has columns {classId Year sName}
“ sName
”是学生表中的参考键
我想使用实体模型 C# 插入数据
谁能告诉我如何插入数据
Table Student has columns {stuId Name Age}
Table School has columns {classId Year sName}
“ sName
”是学生表中的参考键
我想使用实体模型 C# 插入数据
String SchooID = getNewID();
Schools schl = new Schools();
schl.school_reference = SchooID;
schl.school_name = "Ananda Collage";
schl.StudentReference.Value = cecbContext.Students.First(i => i.stud_name == "Josh");
cecbContext.AddToSchools(schl);
cecbContext.SaveChanges();
我以这种方式找到了答案。这对我很成功。非常感谢你们的帮助
试试这个来添加学生:
Student student = new Student(){studId="", Name="", Age=""};
myEntities.Students.AddObject(student);
myEntities.SaveChanges();
添加学校:
School school = new School(){classId="", Year = year, sName=""};
myEntities.Schools.AddObject(school);
myEntities.SaveChanges();
我希望这有帮助。