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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:47:47+00:00 2026-06-05T02:47:47+00:00

i have been using code first technique in ASP.NET MVC3 app. here it is

  • 0

i have been using code first technique in ASP.NET MVC3 app. here it is very basic issue i.e. how to update a navigation property. following is detailed code.

    public class Destination
    {
        public int ID {get;set;}
       // some other properties
        public Country {get;set;}
    }

    public class Country
    {
     int ID {get;set;}
     string Name {get;set;}
    }

    //i have simple structure as above. when i go to update destination entity. Country is not getting updated.even i tried following:

    _db.Entry(Destination.Country).State = System.Data.EntityState.Modified;
    _db.Entry(Destination).State = System.Data.EntityState.Modified;
    //_db.ChangeTracker.DetectChanges();
    _db.SaveChanges();

Secondly when i go for Add it works fine. is there any need to have foriegnKey relationship explicityly required?

  • 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-06-05T02:47:48+00:00Added an answer on June 5, 2026 at 2:47 am

    You can add entity in three ways:

    Calling the Add() method on DbSet. This puts the entity into the Added state, meaning that it will be inserted into the database the next time that SaveChanges() is called.

    context.Destination.Add(yourDestination);
    

    Changing its state to Added.

    context.Entry(yourDestination).State = EntityState.Added;
    

    Adding a new entity to the context by hooking it up to another entity that is already being tracked

    context.Destination.Country.Add(yourCountry);
    

    Regards.

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

Sidebar

Related Questions

I'm writing an ASP.net MVC3 application using Entity Framework Code First and SqlCe4. I
I have been using this code with great success to pull out the first
I have been given some matlab code compiled using the .net compiler. I can
I have been using Entity Framework CTP with Code-First as in this tutorial by
I'm using Entity Framework 4.1 Code First and have been trying to add a
I have a product admin web site that has been generated using ASP.NET Dynamic
We have been using Google Code SVN to store a school project. As we
I am using the following code for the Share Price Application I have been
I have been writing unit tests using NUnit and Moq with my Silverlight code
I have been reading that creating dependencies by using static classes/singletons in code, is

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.