Привет, у меня есть этот запрос на обновление, который работает нормально, но это займет около 3-4 секунд, прежде чем я получу обновление окна сообщения успешно. Не могли бы вы помочь увидеть, что идет не так? Это из-за использования () и отката транзакции?
public void Update()
{
System.Data.Common.DbTransaction transaction = null;
using (JamminDataContext db = new JamminDataContext())
{
try
{
db.Connection.Open();
transaction = db.Connection.BeginTransaction();
db.Transaction = transaction;
#region Update Users
db.Users.Attach(this, GetSingleUserById(this.Id));
db.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, db.Users);
db.SubmitChanges();
#endregion
if (this.RoleId == (int)RoleTypes.Student)
{
#region Update CourseByStudents
foreach (CourseByStudent courseByStudent in this.courseByStudent)
{
if (courseByStudent == null) break;
if (courseByStudent.Id == 0)
{
courseByStudent.CourseUserStatus.UserId = this.Id;
db.CourseUserStatus.InsertOnSubmit(courseByStudent.CourseUserStatus);
db.SubmitChanges();
courseByStudent.StudentId = this.Id;
courseByStudent.CourseUserStatusId = courseByStudent.CourseUserStatus.Id;
db.CourseByStudents.InsertOnSubmit(courseByStudent);
db.SubmitChanges();
}
else
{
if(courseByStudent.CourseUserStatusCopy != courseByStudent.CourseUserStatus.Status
&& ( courseByStudent.CourseUserStatus.Status != null
&& courseByStudent.CourseUserStatus.Date != null))
{
//Insert to CourseUserStatus only when Status is change or add new row of course
courseByStudent.CourseUserStatus.UserId = this.Id;
db.CourseUserStatus.InsertOnSubmit(courseByStudent.CourseUserStatus);
db.SubmitChanges();
courseByStudent.CourseUserStatusId = courseByStudent.CourseUserStatus.Id;
}
courseByStudent.Update();
}
}
#endregion
}
transaction.Commit();
}
catch (Exception ex)
{
if (transaction != null) transaction.Rollback();
Logger.Error(typeof(User), ex);
throw;
}
finally
{
if (db.Connection.State == System.Data.ConnectionState.Open) db.Connection.Close();
}
}
}