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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:03:28+00:00 2026-05-17T03:03:28+00:00

I am new to C# and .NET and I just started to study LINQ

  • 0

I am new to C# and .NET and I just started to study LINQ to SQL, I like it. But.. I found this one very annoying thing about it. Implementing lookUps is very complex because of the “ForeignKeyReferenceAlreadyHasValueException”! There is just NO simple straight-forward way of doing it! I noticed, if I delete all associations between LINQ entities, the “ForeignKeyReferenceAlreadyHasValueException” problem is no more! I am planing to develop small WinForms database applications, with no more then 100 tables…

So my question is:

What do I lose/risk if I use LINQ2SQL but delete all the associations between LINQ entities and keep relations in database ?

  • 1 1 Answer
  • 2 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-17T03:03:29+00:00Added an answer on May 17, 2026 at 3:03 am

    Basically you’ll lose querying support, lazy-loading, IntelliSense, etc. For example, you won’t have things like this if you delete the association between Users and Questions:

    from u in context.Users
    where u.Questions.Count > 2
    select u;
    

    The point of LINQ is to provide you with all the constructs necessary to implement a relational database model within your C# code enabling you to query that model. If you delete all the associations/relationships LINQ to SQL loses it’s purpose.

    Regarding the Exception you got:

    If the association property is
    assigned a value you cannot change the
    foreign key field anymore, you must
    change the relationship by changing
    the association property. For
    example, using Customer and Order from
    Northwind sample database. If the
    ‘Customer’ property on an order is
    assigned a value you can no longer
    manually change the order’s CustomerID
    field, since it must match the PK of
    the customer. You can, however,
    change the ‘Customer’ property
    directly, assigning it a new customer
    instance. This action will
    automatically update the CustomerID
    field to match. By Matt Warren (LINQ to SQL architect)

    This is what you need to do to solve your problem:

    LINQ to SQL ForeignKeyReferenceAlreadyHasValueException error

    For LookUps and LINQ, do this:

    LINQ, Lookups, ForeignKeyReferenceAlreadyHasValueException

    Use this code for example when binding a combobox:

    With cboCategory 
    .DataSource = From Category In db.Categories Order By Category.Name
                  Select Category 
    .DisplayMember = "Name" 
    .ValueMember = "ID"    don't set value member: http://tinyurl.com/d9etoy 
    .DataBindings.Add(New Binding("SelectedItem", ItemBindingSource, "Category")) 
    End With 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am just getting started with this. New to .NET, SQL Server, C#,
I am a seasoned .NET / SQL Server developer. I just started a new
I just started working in a .Net company and I saw this code but
I have just started a new web application with asp.net mvc and sql server
I've just started a new project in ASP.net 4.0 with MVC 2. What I
I just started a new project, and now with ASP.NET MVC being designed in
I am new to asp.net and just started my first project. I heard about
I am new to ASP.NET MVC Forms Authentication and have just started to create
I just started a new job yesterday and this is only my second job
I have just started learning asp.net mvc and one reason of the primary reasons

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.