SqlException: जब सत्र में अन्य थ्रेड चल रहे हों तो नया ट्रांजेक्शन अनुमत नहीं है (Entity Framework)
सभी को नमस्ते! मैं C# और Entity Framework में नया हूँ, एक समझ से परे त्रुटि का सामना करना पड़ा। मैं SQL Server के साथ ASP.NET MVC पर एक सरल एप्लिकेशन लिख रहा हूँ। सेवा में एक मेथड है जो डेटाबेस में कई रिकॉर्ड अपडेट करना चाहिए। मैं `foreach` लूप का उपयोग कर रहा हूँ, और लूप के अंदर प्रत्येक रिकॉर्ड के लिए `SaveChanges()` कॉल कर रहा हूँ। अंत में मुझे यह एक्सेप्शन मिलता है:
**SqlException: New transaction is not allowed because there are other threads running in the session.**
यहाँ सरलीकृत कोड है:
```csharp
public void UpdateOrders(List orders)
{
using (var context = new MyDbContext())
{
foreach (var order in orders)
{
order.Status = "Processed";
context.Entry(order).State = EntityState.Modified;
context.SaveChanges(); // दूसरे इटरेशन पर यहाँ त्रुटि
```