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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:12:49+00:00 2026-05-16T02:12:49+00:00

In the following code, I don’t believe I am changing the foreign key, but

  • 0

In the following code, I don’t believe I am changing the foreign key, but I could be wrong. When I run it, I get the exception:

ForeignKeyReferenceAlreadyHasValueException

Here is the code:

UsersModule um = dc.UsersModules.Where(x => x.UserId == IdParam).FirstOrDefault();
int oldModuleId = um.ModuleId;
string oldModule = um.Module.ModuleName;

The error is thrown on the line:

string oldModule = um.Module.ModuleName

I don’t know why I am getting this error because I am just trying to store the value of ModuleName into string oldModule, not change um.Module.ModuleName

  • 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-16T02:12:50+00:00Added an answer on May 16, 2026 at 2:12 am

    LINQ works based on relational entities. So, whenever you need to set/read a foreign key value, it must be done by setting/reading the foreign entity instelad. Which means that shortcuts such as “Module.ModuleName” does not work very well.

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

Sidebar

Related Questions

The following code runs successfully with no errors, but I still don't get the
In the following code I want to use the dilate function but I don't
I tried the following code. Although I don't get any errors, it did not
When I run the following Code it crashes at the last line. I don't
The following source code are used to implement product/consumer pattern, but they don't work
The following code causes a stack overflow but I don't see why... int _tmain(int
Following code has to be used in the main-function, but I don't know how
I am using the following code but don't know why thumbnails are not created.
The following code: oc.CreateTablesAsync(typeof(ODataService.UserInformationListItem), typeof(ODataService.CategoriesItem), typeof(ODataService.PostsItem)); Gives me this exception: System.NotSupportedException: Don't know about
I have the following code. I feel like I'm being redundant but don't know

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.