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 154111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:55:15+00:00 2026-05-11T09:55:15+00:00

edit: in case anyone is wondering, the actionhandler invokes code that creates and disposes

  • 0

edit: in case anyone is wondering, the actionhandler invokes code that creates and disposes the same kind of datacontext, in case that might have anything to do with this behaviour. the code doesn’t touch the MatchUpdateQueue table, but i figure i should mention it just in case.

double edit: everyone who answered was correct! i gave the answer to the respondent who suffered most of my questioning. fixing the problem allowed another problem (hidden within the handler) to pop up, which happened to throw exactly the same exception. whoops!

I’m having some issues with deleting items in LINQ. The DeleteOnSubmit call in the code below causes a LINQ Exception with the message ‘Cannot add an entity with a key that is already in use.’ I’m not sure what I’m doing wrong here, it is starting to drive me up the wall. The primary key is just an integer autoincrement column and I have no other problems until I try to remove an item from the database queue. Hopefully I’m doing something painfully retarded here that is easy to spot for anyone who isn’t me!

static void Pacman() {     Queue<MatchUpdateQueue> waiting = new Queue<MatchUpdateQueue>();      events.WriteEntry('matchqueue worker thread started');      while (!stop)     {         if (waiting.Count == 0)         {             /* grab any new items available */             aDataContext db = new aDataContext();             List<MatchUpdateQueue> freshitems = db.MatchUpdateQueues.OrderBy(item => item.id).ToList();              foreach (MatchUpdateQueue item in freshitems)                 waiting.Enqueue(item);             db.Dispose();         }         else         {             /* grab & dispatch waiting item */             MatchUpdateQueue item = waiting.Peek();             try             {                 int result = ActionHandler.Handle(item);                 if (result == -1)                     events.WriteEntry('unknown command consumed : ' + item.actiontype.ToString(), EventLogEntryType.Error);                  /* remove item from queue */                 waiting.Dequeue();                  /* remove item from database */                 aDataContext db = new aDataContext();                 db.MatchUpdateQueues.DeleteOnSubmit(db.MatchUpdateQueues.Single(i => i == item));                 db.SubmitChanges();                 db.Dispose();             }             catch (Exception ex)             {                 events.WriteEntry('exception while handling item : ' + ex.Message, EventLogEntryType.Error);                 stop = true;             }         }          /* to avoid hammering database when there's nothing to do */         if (waiting.Count == 0)             Thread.Sleep(TimeSpan.FromSeconds(10));     }      events.WriteEntry('matchqueue worker thread halted'); } 
  • 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. 2026-05-11T09:55:15+00:00Added an answer on May 11, 2026 at 9:55 am

    You could do something to the effect of

    db.MatchUpdateQueues.DeleteOnSubmit(db.MatchUpdateQueues.Single(theItem => theItem == item)); 

    Just a note as other answers hinted towards Attach.. you will not be able to use attach on a context other then the original context the item was received on unless the entity has been serialized.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer is it this? What about this then... LinqDataSource1.Where = "MyDateColumn… May 11, 2026 at 11:34 pm
  • Editorial Team
    Editorial Team added an answer Here are some VBScript examples to extract the data you… May 11, 2026 at 11:34 pm
  • Editorial Team
    Editorial Team added an answer Here is an example (including creating an event) for ASP.NET… May 11, 2026 at 11:34 pm

Related Questions

I was wondering whether using a Belt and Braces (Suspenders) approach to programming -
I am looking to set up a central point of control for settings that
I'm wondering which collection-type in System.Collections.Generic will support this scenario, if there is one:
I have a List<T> that I want to search not for a given item

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.