2013-03-26 22 views
-1
用於插入數據
+0

您的數據庫設計看起來不太好。你在「學校」表中有「sName」嗎? – Dilshod 2013-03-26 14:38:12

+0

你是說'sName'與'Student'中的'Name'鏈接? – Joetjah 2013-03-26 14:55:14

回答

0
   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(); 

我以這種方式找到了答案。這對我成功了。非常感謝您的幫助夥伴

0

數據嘗試使用此方法添加學生:

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(); 

我希望這會有所幫助。

+1

其實我需要添加數據到學校表?其中有學生表的參考? – Gayashan 2013-03-26 14:49:10

相關問題