0

I just performing Insert and Read operation using EF with SP. I've two SP, one for read and another for Inserting. When I execute this operation one by one, I am getting this error on second SP

New transaction is not allowed because there are other threads running in the session.

Code

var students = db.GetStudentByID(1);

Student_Mast model = new Student_Mast();
model.First_Name = "John";
model.Last_Name = "Abraham";
model.Roll_No = 2;
db.Student_Mast.Add(model);
db.SaveChanges();

I've checked many post, but all refering to foreach loop.

Ubiquitous Developers
  • 3,637
  • 6
  • 33
  • 78

1 Answers1

1

The students variable isn't a collection of objects, it's an enumerator that can return objects. While you use the enumerator, the source has to remain open.

var students = db.GetStudentByID(1).ToList();

Please refer this link for the brief. go here

Community
  • 1
  • 1
Krunalsinh
  • 240
  • 1
  • 13