I am new to Linq to SQL, but I am surprised at the problems I am having updating a table. From reading various sources I think the problem I get is a problem with the ORM mapping, but even so, given I am using VS 2008 and creating my dbml via a LINQ to SQL class, I do not expect this. So what is happening is that when I update and/or insert a row, lots of other rows get created in the table as well. I cannot predict what the pattern is when this happens, sometimes it doesn't happen. I am not sure the code below says very much about what the problem is, but I reproduce it here;
public static void UpdateDailyTimeRecorded(
int dailyTimeRecordedId, bool amFlag, string timeIn, string timeOut)
{
DailyTimeRecorded dtr = GetDailyTimeRecorded(dailyTimeRecordedId);
if (amFlag == true)
{
dtr.MorningTimeIn_HH = Convert.ToInt32(timeIn.Substring(0, 2));
dtr.MorningTimeIn_MM = Convert.ToInt32(timeIn.Substring(3, 2));
dtr.MorningTimeOut_HH = Convert.ToInt32(timeOut.Substring(0, 2));
dtr.MorningTimeOut_MM = Convert.ToInt32(timeOut.Substring(3, 2));
dtr.MorningLeaveFlagId = 0;
}
else
{
dtr.AfternoonTimeIn_HH = Convert.ToInt32(timeIn.Substring(0, 2));
dtr.AfternoonTimeIn_MM = Convert.ToInt32(timeIn.Substring(3, 2));
dtr.AfternoonTimeOut_HH = Convert.ToInt32(timeOut.Substring(0, 2));
dtr.AfternoonTimeOut_MM = Convert.ToInt32(timeOut.Substring(3, 2));
dtr.AfternoonLeaveFlagId = 0;
}
try
{
db.SubmitChanges();
}
catch (ChangeConflictException)
{
db.ChangeConflicts.ResolveAll(RefreshMode.KeepChanges);
}
}
I put a breakpoint on the line db.SubmitChanges(); and the rows get inserted at this point for sure, not before and not some code afterwards.