我創建了一個1:多關係,並且通過ADO.net進行的批量插入不會傳播到我的LINQ-to-SQL數據上下文。C#Linq-to-SQL在Ado.net之後沒有更新插入
例如
TABLE School
int schoolId
int maxStudents
...
TABLE Students
int studentId
int schoolId
DateTime birthdate
...
如果我批量添加,比方說,500名學生到Students
表,我的數據上下文不會更新。學生。它只是說.Students.Count()== 0
編輯下面是一個例子:
// Create a Repository
Repository Repo = new Repository();
string[] schoolNames = GetSchoolNames();
// Pull in the schools.
IEnumerable<School> schools = Repo.GetSchools(schoolNames);
foreach (School school in schools) school.DoSomeDirectDBWork();
schoolNames = schools.Select(school => school.name).ToArray();
Repo.Dispose(); // Flush/Close/Dispose
Repo = new Repository(); // New repository, new data context.
schools = Repo.GetSchools(schoolNames);
// ** THE SCHOOLS HAVE NO STUDENTS AT THIS POINT IN THE CODE.
// ** <SAD FACE>
請在代碼中顯示您要做的插入。 – Yuck
哪個數據庫供應商? – sgtz
@sgtz LINQ-to-SQL = SQL服務器,除非你正在做壞事 –