Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8494781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:23:34+00:00 2026-06-10T23:23:34+00:00

I am Using Linq to Entity MVC and when I am trying to delte

  • 0

I am Using Linq to Entity MVC and when I am trying to delte records from database I am getting this Exception.

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

My code:

if (Request.Form["Enroll"] != null)
{
    string[] selected = Request.Form["Enroll"].Split(',');

    if (selected != null)
    {
        if (selected.Count() != 0)
        {
            int k = 0;
            foreach (var item in selected)
            {
                var TraineeId = Convert.ToInt32(item[k].ToString());
                var sessionid = Convert.ToInt32(Session["user"].ToString());

                var id = db.EnrollTrainee.Where(i => i.TraineeID == TraineeId
                                                && i.TrainerID == sessionid);

                if (id != null)
                {
                    foreach (var a in id)
                    {
                        //db.Database.Connection.Close();
                        EnrollTrainee delete = db.EnrollTrainee.Find(a.id);
                        db.EnrollTrainee.Remove(delete);
                        db.SaveChanges();   //Getting Exception Here                                        
                    }
                }
                k++;
            }
        }
    }
    populatelistbox();
    return View();
}

Please Help.!!!
Thanks in Advance.!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:23:36+00:00Added an answer on June 10, 2026 at 11:23 pm

    Got a very good solution in this nice Blog.

    Solution of my problem:-

     if (Request.Form["Enroll"] != null)
                    {
                        string[] selected = Request.Form["Enroll"].Split(',');
    
                        if (selected != null)
                        {
                            if (selected.Count() != 0)
                            {
                                int k = 0;
                                foreach (var item in selected)
                                {
                                    var TraineeId = Convert.ToInt32(item[k].ToString());
                                    var sessionid = Convert.ToInt32(Session["user"].ToString());
    
                                    var id = db.EnrollTrainee.Where(i => i.TraineeID == TraineeId
                                                                    && i.TrainerID == sessionid);
                                    var idlist = id.ToArray<EnrollTrainee>();//Added New Line
    
                                    if (idlist != null)
                                    {
                                        foreach (var a in idlist)
                                        {
                                            EnrollTrainee delete = db.EnrollTrainee.Find(a.id);
                                            db.EnrollTrainee.Remove(delete);
                                            db.SaveChanges();                                           
                                        }
                                    }
                                    k++;
                                }
                            }
                        }
                        populatelistbox();
                        return View();
                    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Entity Framework. I am trying to get the results from linq
I'm not using LINQ-to-SQL or Entity Framework bits in a web app, and have
I recently switched from using Linq to Sql to the Entity Framework. One of
I'm using an ADO.NET Entity Model which I'm trying to query using LINQ. The
This code using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity; using System.Data.Entity.ModelConfiguration;
I have a database and I am using the Entity Framework with Linq 2
I'm trying to return new data to jTable from my entity framework db context.
The goal: I'm trying to use the new Entity Framework 4.1 DbContext API (using
newbie writing, I'm new to MVC 2 C# and using EntityFramework with LINQ. In
I am trying to handle the http-post from a web form using MVC 2s

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.