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

The Archive Base Latest Questions

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

I’ve recently been reading Louis Davidson’s book on Sql Server Database Design and found

  • 0

I’ve recently been reading Louis Davidson’s book on Sql Server Database Design and found it quite informative. I’ve picked up on alot of concepts that I didn’t previously know alot (or anything) about. Primarily – I picked up on a way to set up database relationships that I hand’t tried before.

Basically you use a surrogate key as the tables PK (an auto incremented id field) and then set up one or more Alternate Keys consisting of one or more Unique keys. Theese alternate kays would then be the values used for relationships (or the PK, if that makes more sense for the given relationship).

I remodelled an old database that was suffering from some data inconsitencies due to poor design to implement this, to me, new way of thinking.

On a database level it works great. Tha relationships function the way they’re supposed to and the constraints are enforced in a consistent, reliable manner.

HOWEVER

I cannot get it to work properly in either the Entity Framework or in Linq to Sql classes. I read that in V1 of EF, it just flat out won’t support this kind of relationship – so I moved to Linq to Sql to see if things would work out better. They seemingly did, as I got all the relationships automatically mapped out when I imported the classes from my database. The problem is that I can’t save data to the database because of InvalidCastOperation exceptions as soon as I try to save data.

So I have a couple of questions:

  1. Is this a limitation in Linq To Sql?
  2. If so, is there a way to work around it? Preferebly without implementing sprocs for save, update and delete – type safety is something I would like to keep.
  3. Is this way of designing database relationships ‘correct’ and/or a good practice?

I hope someone can shed some light on this, as I’m getting quite frustrated about it. I can’t really find any good material on the subject online – so hopefully someone here has an answer or can point me in the right direction.

Thanks alot!

EDIT – Solution.

What I ended up doing was this – I went back to using the Entity Framework in conjunction with a redesign of the database schema. I remodeled the relationships to rely on primary keys rather than alternate keys, in most cases. Where that was not an option – I made some modifications to the EF layout. I implemented the relationship that relied on the AK’s – at which time EF complains. To get around that I had to delete the foreign key property on the many side of the relationship at which point EF accepts the relationship.

  • 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-11T14:15:43+00:00Added an answer on May 11, 2026 at 2:15 pm

    1) Yes.

    2) If you can mark your alternate key as primary in the L2S model and unmark the real PK as PK then it will work.

    3) From the db perspective there’s nothing wrong, but as you have noticed it is not supported by L2S or EF. Personally I prefer to always have FKs pointing to the PK and only use AKs for lookups.

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

Sidebar

Ask A Question

Stats

  • Questions 93k
  • Answers 93k
  • 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 I'm making a few assumptions about what your doing (such… May 11, 2026 at 6:36 pm
  • Editorial Team
    Editorial Team added an answer The basic best practice recommendation would be to use per-call,… May 11, 2026 at 6:36 pm
  • Editorial Team
    Editorial Team added an answer You can set the width of a table column using… May 11, 2026 at 6:36 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.