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

  • Home
  • SEARCH
  • 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 334933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:06:06+00:00 2026-05-12T10:06:06+00:00

I have two tables, A and B and a simple table, X, that maintains

  • 0

I have two tables, A and B and a simple table, X, that maintains a relationship between the two. X contains AID and BID as its primary key.

I’m using Linq-to-Sql to insert a relationship like:

public void InsertRelationship(int y, int z) {
  DataContext.X.InsertOnSubmit(new x { AID = y; BID = z });
}

The problem is that two calls to InsertRelationship() can be invoked in extreme circumstances so an exception will be thrown due to the duplicate record. This doesn’t matter to me as I know the relationship then exists so I’m ignoring the exception.

Is it okay to ignore an exception in this case or is it still bad practice? Should I check that the relationship doesn’t already exist before the insert? How would this affect performance?

Update

The duplicate call to InsertRelationship() cannot be avoided. It is a web application so I cannot stop the user opening two separate windows and invoking the method twice for example. The method would not be invoked twice through typical user interaction but I’m programming against the extreme case here. The percentage of duplicates will probably be very low but I can’t be sure of exact numbers yet.

  • 1 1 Answer
  • 1 View
  • 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-05-12T10:06:06+00:00Added an answer on May 12, 2026 at 10:06 am

    The main problem with just ignoring the exception is that an exception may be thrown for other problems not related at all with a duplicate record which you don’t want to hide, like SQL timeouts or deadlocks among others.

    The best solution would be to construct your application so the dupes insertion does not happen, the next best would be to check for their existence before doing the insertion.

    If performance is critical, the dupes insertion cannot be avoided, the ratio of dupes insertion to working insertion is very small and you can tell that the raised exception is only due to the duplicate problem, you might be better off just catching the exception and ignoring it. But that’s an if with a lot of conditions 🙂

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

Sidebar

Related Questions

I have two simple tables in my database. A card table that contains Id,
I have two tables, one that contains volunteers, and one that contains venues. Volunteers
I have two tables, one has primary key other has it as a foreign
I have a simple database with two tables. Users and Configurations. A user has
I have two tables that are joined together. A has many B Normally you
We have two Tables: Document: id, title, document_type_id, showon_id DocumentType: id, name Relationship: DocumentType
I have two tables say, t1 and t2 that have t1.t1_id and t2.t2_id as
I have two tables that are related, which, for the purpose of this question,
I have two tables: Table 1 id app_name app_id 1 name1 12001 2 name2
I have a two simple tables users +----+--------+-----------+ | id | gender | birthdate

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.