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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:52:59+00:00 2026-05-15T19:52:59+00:00

Context: ASP.NET MVC 2.0, Linq-to-Sql, .Net 3.5, IIS7, MS SQL 2008 I’m working on

  • 0

Context: ASP.NET MVC 2.0, Linq-to-Sql, .Net 3.5, IIS7, MS SQL 2008

I’m working on a game fan site.

I have a table as follows:

ToonId int (primary key)
RealmId (FK into Realms table)
OwnerId int (FK into Users table)
ToonName nvarchar(50)
IsMain bit

That is a single user may own multiple toons on multiple realms (aka servers), but exactly one toon must be marked as main per user per realm (only for realms where there is at least one toon).

Suppose I have two toons (on one realm):
Foo (marked as main)
and
Bar (not main)

I want to change my main, and for that I do something like:
Foo.IsMain = false
Bar.IsMain = true

I’m using Linq-to-SQL.

Question: how can I make said transition without entering a state when I have either more than one or zero main toons.

Note: I have a materialized view (filtered by IsMain = 1) that defines a composite key (OwnerId, RealmId), as such when I do main-toon transition I get “unique key violation” exception from that materialized view.

I have tried using transaction, but I still get exception on ‘db.SubmitChanges()’.

Option 2: I suspect that I have the flaw in the database design (what’s the name of this flaw?). Should I create a mapping table?

OwnerId, RealmId -> ToonId
  • 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-05-15T19:52:59+00:00Added an answer on May 15, 2026 at 7:52 pm

    Question 1

    You need to use transactions.

     DBDataContext db = new DBDataContext();
     using (TransactionScope ts = new TransactionScope())
     {
         try
         {
             Toon toon1 = db.Toons.First(p => p.ToonId == 4);
             Toon toon2 = db.Toons.First(p => p.ToonId == 5);
             toon1.IsMain = false;
             toon2.IsMain = true;
             db.SubmitChanges();
             ts.Complete();
         }
         catch (Exception e)
         {
            Console.WriteLine(e.Message);
         }
    }
    
    • Transactions (LINQ to SQL)
    • How to: Bracket Data Submissions by Using Transactions (LINQ to SQL)
    • How to create a LINQ to SQL Transaction?

    Question 2

    You need to think about your design a bit more.

    Step 1

    It is a player who has a main Toon so I would put a MainToonId on your Users table and remove your IsMain from your Toon table.

    After this your tables would be Users ( Existing Stuff, MainToonId ), Realms ( Existing Stuff), Toons (ToonId, RealmId, OwnerId, ToonName )

    Step 2

    As you’ve suggested you could probably move the Realm/Owner/Toon link to its own table (or even ToonOwner and ToonRealm tables). The link information is related to Toon, but it’s not an identifying part of being a Toon. The resolution of this “flaw” is normalisation and a database that needs it is described as “needing normalisation”. However, this step is completely optional in this case and may be over-normalising for your needs.

    If you did go with one matchup table, the new table would have a PK of the 3 values combined (if you are a natural keyer) otherwise a standard PK and a UNIQUE on the 3 values (if you are not a natural keyer). You should also have a UNIQUE on ToonId as each Toon can presumably only belong to one Realm or Owner.

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

Sidebar

Related Questions

No related questions found

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.