I want modified SQL data using linq, but when I modified, I got into trouble.
I get this error:
New transaction is not allowed because there are other threads running in the session.
and this is my linq in C#
for (int i = 1; i < st.Count(); i++)
{
string Lesson = i.ToString();
var query = db.YearCourse_105008
.Where(o => o.Day == Day && o.Lesson == Lesson)
.Select(o => new
{
O_GUID = o.OpenCourseGUID,
Lesson = o.Lesson
});
foreach (var item in query)
{
var PK = db.YearCourse_105008.Find(item.O_GUID);
PK.Day = Day;
PK.RC_MAJORCODE = st[i];
PK.Lesson = i.ToString();
db.Entry(PK).State = EntityState.Modified;
db.SaveChanges();
}
}