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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:14:25+00:00 2026-05-19T00:14:25+00:00

I am battling to work out how to handle foriegn keys with Entity Framework,

  • 0

I am battling to work out how to handle foriegn keys with Entity Framework, when editing or adding a new record. For example, I have a person table, which has a timezone_id linking to my timezone table.

But the model seems to not include timezone_id. I see it’s a new way of doing things, but … how do I store my record?

My method:

 public static string CreateUser(string username, string email, string password, string firstname, string surname, int timezoneId)
    {
        user u = new user();
        u.surname = surname;
        u.firstname = firstname;
        u.email = email;
        u.password = password;
        u.username = username;
        Db.AddTousers(u);

        Db.SaveChanges();

        return username;

    }

I can’t do u.timezone_id = timezoneid;

I only have u.timezone (which seems to be the actual entity), and u.timezoneReference, which I am not sure what to do with.

  • 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-19T00:14:26+00:00Added an answer on May 19, 2026 at 12:14 am

    I think you have to fill in the timezone entity from the database, i.e.

    u.timezone = DB.TimezoneSet.FirstOrDefault(tz => tz.Id == timezoneid);
    

    assuming you’ve generated the set name with EF3; it’ll be DB.Timezones by default in EF4. If this is EF4 then you can also regenerate your EDMX for that table with ID columns included too – there’s an option on the front page of the wizard.

    The TimezoneReference property is used to test whether child entities have been loaded, force them to load, etc.

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

Sidebar

Related Questions

Sorry for the wordy title - I am battling to work out if my
I have seen programmers battling it out with really complex mathematical problems in their
I am new to Java and have been battling this problem with google-fu ad
Am new to php... I have been battling on my dynamic checkboxes in such
I've been battling to get this right...basically I have the following HTML setup: <div
I'm battling a really weird problem here. I have a Windows 2008 R2 server
I am currently battling with the anythingslider jquery - https://github.com/ProLoser/AnythingSlider/wiki , I have almost
I'm battling out of memory issues with my application and am trying to get
I've been battling with this issue for a couple of days now. I have
I'm battling an error I don't quite understand. I have a class in Java,

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.