EF6: How can I get navigation properties automatically updated?

I've defined the following entities:
public abstract class EntityBase
public int Id { get; set; }
public string Name { get; set; }
public class Person : EntityBase
public virtual HashSet<Message> Messages { get; set; }
public int CountryId { get; set; }
public virtual Country Country { get; set; }
public class Message : EntityBase
public string Text { get; set; }
public int PersonId { get; set; }
public Person Person { get; set; }
public class Country : EntityBase
internal class TestContext : DbContext
public DbSet<Person> Persons { get; set; }
public DbSet<Country> Countries { get; set; }
Here's my problem: While the Messages.Person navigation property gets automatically updated according to the Messages.PersonId
foreign key property value when my changes get saved to the database, the Person.Country
navigation property remains null although the Person.CountryId
foreign key property is != 0.
Why is this happening? Why does the Messages.Person navigation property get aligned with the Messages.PersonId
foreign key property automatically while the Person.Country navigation property does not get aligned with the Person.CountryId
foreign key property?
These are the entity values before SaveChanges() is called:
person.CountryId = 1
person.Country = null
message.PersonId = 1
message.Person = null
And these are the entity values after SaveChanges() is called:
person.CountryId = 1
person.Country = null
message.PersonId = 1
message.Person = { Id = 1, Name = "Test" }
Your help is appreciated.
Still people out there alive using the keyboard?
Working with SQL Server/Office/Windows and their poor keyboard support they seem extinct...

Thank you for replying, Fred.
Here's the unit test code I'm using (it calls into a repository which more or less simply calls DbSet<Entity>::Add()
and SaveChanges();.
[TestMethod]
public void MessageDbTest()
using (Repository<Person> rp = new Repository<Person>(true))
Person p;
Message m;
BusinessLayer.TestContext.CreateNewDB();
rp.AddOrUpdate(p = new Person("Hello", 1));
Assert.AreEqual<int>(1, p.Id);
Assert.AreEqual<string>("Hello", p.Name);
m = new Message("Hello, too", p.Id, "This is a long test message.");
p.Messages.Add(m);
rp.AddOrUpdate(p);
Assert.AreSame(m, p.Messages.Single());
Assert.IsNotNull(m.Person);
Assert.AreEqual<int>(1, m.Id);
Assert.AreEqual<string>("Hello, too", m.Name);
Assert.AreEqual<string>("This is a long test message.", m.Text);
p = rp.GetItem(1);
p.Messages.Single().Name = "This works, too";
rp.AddOrUpdate(p);
[TestMethod]
public void CountryDbTest()
using (Repository<Person> rp = new Repository<Person>(true))
Person p;
Message m;
BusinessLayer.TestContext.CreateNewDB();
rp.AddOrUpdate(p = new Person("Hello", 1));
Assert.AreEqual<int>(1, p.Id);
Assert.AreEqual<string>("Hello", p.Name);
Assert.AreEqual<int>(1, p.CountryId);
Assert.IsNotNull(p.Country); // ** fails ! ***
Following is a number of screenshots, depicting the entities' properties.
Please notice the highlighted navigation property values in the Watch window on the right.
You will notice that while the Messages.Person navigation property gets aligned with the Messages.PersonId
foreign key property, the Person.Country navigation property does not get aligned with the Person.CountryId
foreign key property when TestContext::SaveChanges() is called:
Still people out there alive using the keyboard?
Working with SQL Server/Office/Windows and their poor keyboard support they seem extinct...

Similar Messages

  • How can I get mail to automatically update calendar invites without actually opening calendar and disrupting my work?

    I like mail to continue placing new invitations into my calendar so that I can accept (or reject) them when convenient.  However I would like to be able to work in an application without being disrupted whenever someone sends me lots of invitations.  Is there a way to prevent mail from opening calendar and making it the main screen?
    Thanks.

    Most likely the library blocks the ports needed for sending and receiving mail. Check with them.
    ''some Thunderbird setting that prevents Thunderbird from working, maybe because it considers this a vulnerable network.''
    There is no such Thunderbird setting.

  • How can I get Firefox to automatically open a new search in a new tab please?

    How can I get Firefox to automatically open a new search in a new tab please? [Without me manually opening the tab]

    For searches from the Search Bar, when you use the Enter key.
    Type '''about:config''' in the URL bar and hit Enter. <br />
    ''If you see the warning, you can confirm that you want to access that page.''
    Pref = '''browser.search.openintab''' = double-click to toggle to '''true'''

  • How can i say yes to automatic updates when they stop my wireless dlink to Virgin home broadband from getting on the internet and then i have to do a system restore to the day before the update to get it back to normal?!? Frustrated

    how can i say yes to automatic updates when they stop my wireless dlink to Virgin home broadband from getting on the internet and then i have to do a system restore to the day before the update to get it back to normal?!? Frustrated
    == This happened ==
    Not sure how often
    == automatic updates go on my computer, say if i click yes to update when shutting down

    You have 10.6 on that machine, I suggest you stick with it for performance, third party hardware and software reasons as long as possible.
    Consider 10.8 (not 10.7) when it's released, because 10.7 and 10.8 will require a new investment in software and newer third party hardware as it requires newer drivers the old machines won't have. (forced upgrade because of software, really nice of them)
    http://roaringapps.com/apps:table
    Far as your Safari problem do these things until it's resolved:
    1: Software Update fully under the Apple menu.
    2: Check the status of your plug-ins and update (works for all browsers) also install Firefox and see if your problems continue. You should always have at least two browsers on the machine just in case one fails.
    https://www.mozilla.org/en-US/plugincheck/
    Flash install instructions/problem resolution here if you need it.
    How to install Flash, fix problems
    3: Install Safari again from Apple's web site
    https://www.apple.com/safari/
    4: Run through this list of fixes, stopping with #16 and report back before doing #17
    Step by Step to fix your Mac

  • How can I get the 23 July update to load onto my iPad. I haven't been able to access my documents or work for weeks and need to use it. Has anyone else had similar problems?

    How can I get the 23 July update to load onto my iPad. I haven't been able to access my documents or work for weeks and need to use it. Has anyone else had similar problems?

    Hello Arthur,
    Thank you for the reply.
    You were correct that deleting the app and reinstalling it was the only thing to make it work but unfortunately I lost all the documents I made, even though they were backed up to iCloud before i deleted the app. At the same time as deleting pages I had to delete keynote and numbers too, so I've lost all the documents in them too.
    The mb of data which was assigned to each programme in iCloud has reduced, so. I guess they are gone for good. Is there any other way to reaccess them?
    Not your fault but I am a bit fed up the the iPad. I have lost work that I've done and have no other copy apart from what was in iCloud, as I don't have a printer and couldn't email them too myself as I couldn't get into the programme and  i've also got episodes of tv series I purchased that I can't download and albums that are half downloaded with songs missing, so I feel a bit swindled out of time and money and am going back to DVD ,  pen and paper and CDs .
    Instead of using iCloud I guess the only way to make sure I don't loose any more documents it to email them to myself each time I save them on the iPad. Is there anything else you could suggest please?
    I don't have any other apple products apart from iPods, so I can't access the iCloud on anything else can I?
    Thanks
    Amanda

  • I have an old apple id that i havent used for years. For some reason i have updates on my mac i cannot do unless i sign onto that old account. It uses an old e mail account i no longer use or have access to. How can i get to do these updates?

    I have an old apple id that i havent used for years. For some reason i have updates on my mac i cannot do unless i sign onto that old account. It uses an old e mail account i no longer use or have access to. How can i get to do these updates?

    its very specific.
    If you are seeing the old Apple ID with regard to this Mac, then it would seem that somehow you have incorporated the ID in the setup of this new Mac.
    Iphoto i use never used imovie.
    If you began using iPhoto without having Accepted it into your Apple ID, then that would explain why you are unable to update the app. If any of the iLife apps are used without Accepting them into your Apple ID, the ability to accept them will lapse and you will not be able to update them.

  • If I can't download an update for an App Store purchase because I don't have OS X 7, how can I get rid of the update reminder?

    If I can't download an update for an App Store purchase because I don't have OS X 7, how can I get rid of the update reminder?

    http://www.apple.com/support/mac/app-store/contact.html?form=account

  • How can I get list properties using SharePoint CSOM

    Hi Team,
    I am using SharePoint CSOM to read SharePoint Discussion board.I need discussion discription and created by and Discussion list Title etc.
    But I am unable to read those. I saw below message for discussion list in immediate window while debugging.
    DiscussionList
    {Microsoft.SharePoint.Client.List}
    base {Microsoft.SharePoint.Client.SecurableObject}: {Microsoft.SharePoint.Client.List}
    AllowContentTypes: 'DiscussionList.AllowContentTypes' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    BaseTemplate: 'DiscussionList.BaseTemplate' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    BaseType: 'DiscussionList.BaseType' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    BrowserFileHandling: 'DiscussionList.BrowserFileHandling' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    ContentTypes: {Microsoft.SharePoint.Client.ContentTypeCollection}
    ContentTypesEnabled: 'DiscussionList.ContentTypesEnabled' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    Created: 'DiscussionList.Created' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    DataSource: 'DiscussionList.DataSource' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    DefaultContentApprovalWorkflowId: 'DiscussionList.DefaultContentApprovalWorkflowId' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    DefaultDisplayFormUrl: 'DiscussionList.DefaultDisplayFormUrl' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    DefaultEditFormUrl: 'DiscussionList.DefaultEditFormUrl' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    DefaultNewFormUrl: 'DiscussionList.DefaultNewFormUrl' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    DefaultViewUrl: 'DiscussionList.DefaultViewUrl' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    Description: 'DiscussionList.Description' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    Direction: 'DiscussionList.Direction' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    DocumentTemplateUrl: 'DiscussionList.DocumentTemplateUrl' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    DraftVersion
    EffectiveBasePermissions: 'DiscussionList.EffectiveBasePermissions' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    EnableAttachments: 'DiscussionList.EnableAttachments' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    EnableFolderCreation: 'DiscussionList.EnableFolderCreation' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    EnableMinorVersions: 'DiscussionList.EnableMinorVersions' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    EnableModeration: 'DiscussionList.EnableModeration' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    EnableVersioning: 'DiscussionList.EnableVersioning' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    Fields: {Microsoft.SharePoint.Client.FieldCollection}
    ForceCheckout: 'DiscussionList.ForceCheckout' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    Forms: {Microsoft.SharePoint.Client.FormCollection}
    HasExternalDataSource: 'DiscussionList.HasExternalDataSource' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    Hidden: 'DiscussionList.Hidden' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    Id: 'DiscussionList.Id' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    ImageUrl: 'DiscussionList.ImageUrl' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    IsApplicationList: 'DiscussionList.IsApplicationList' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    IsCatalog: 'DiscussionList.IsCatalog' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    IsSiteAssetsLibrary: 'DiscussionList.IsSiteAssetsLibrary' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    ItemCount: 'DiscussionList.ItemCount' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    LastItemDeletedDate: 'DiscussionList.LastItemDeletedDate' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    LastItemModifiedDate: 'DiscussionList.LastItemModifiedDate' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    MultipleDataList: 'DiscussionList.MultipleDataList' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    NoCrawl: 'DiscussionList.NoCrawl' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    OnQuickLaunch: 'DiscussionList.OnQuickLaunch' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    ParentWeb: {Microsoft.SharePoint.Client.Web}
    ParentWebUrl: 'DiscussionList.ParentWebUrl' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    RootFolder: {Microsoft.SharePoint.Client.Folder}
    SchemaXml: 'DiscussionList.SchemaXml' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    ServerTemplateCanCreateFolders: 'DiscussionList.ServerTemplateCanCreateFolders' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    TemplateFeatureId: 'DiscussionList.TemplateFeatureId' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    Title: 'DiscussionList.Title' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    UserCustomActions: {Microsoft.SharePoint.Client.UserCustomActionCollection}
    ValidationFormula: 'DiscussionList.ValidationFormula' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    ValidationMessage: 'DiscussionList.ValidationMessage' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
    Views: {Microsoft.SharePoint.Client.ViewCollection}
    WorkflowAssociations: {Microsoft.SharePoint.Client.Workflow.WorkflowAssociationCollection}
    Please let me know how can I get all discussion Properties.
    Krishnasandeep

    Here is the code snippet which is working
    ClientContext Context = new ClientContext(siteurl);
    Context.AuthenticationMode = ClientAuthenticationMode.Default;
    List DiscussionList = Context.Web.Lists.GetByTitle("4gl-adapter");
    CamlQuery query = CamlQuery.CreateAllFoldersQuery();
    ListItemCollection itemCollection = DiscussionList.GetItems(query);
    Context.Load(itemCollection);
    Context.ExecuteQuery();
    foreach (ListItem thread in itemCollection)
    string threadTitle = thread["Title"].ToString();
    string threadBody = thread["Body"].ToString();
    But if try to below code,
    String DiscussionDesc = DiscussionList.Description;
    I am getting exception.
    Let me know if I am doing wrong anywhere.
    Krishnasandeep

  • How can I get system properties?

    Hello,
    How can I get the system properties like %JAVA_HOME% in my java codes, for example, I want to print it like this.
    System.out.println("%JAVA_HOME%");
    but it doesn't work!
    Please give me a hand!

    To pass the Operating system environment variable to the Java "environment variables", you have to explicitely pass them on the command line eg.
    java -Dmyjava.home=%JAVA_HOME% myClass
    then, in your code use
    String JAVA_HOME = System.getProperty ( "myjava.home" );regards,
    Owen

  • How can I get my iPod to update when it says the server cannot be connected?

    Whenever I try to update my iPod it says, "The iPod software update server could not be contacted. Make sure your network settings are correct and your network connection is active, or try again later." It does this every time. How can I get it to update? Any help is much appreciated, thanks!

    Update Server
    Try:
    - Powering off and then back on your router.
    - iTunes for Windows: iTunes cannot contact the iPhone, iPad, or iPod software update server
    - Change the DNS to either Google's or Open DNS servers
    Public DNS — Google Developers
    OpenDNS IP Addresses
    - For one user uninstalling/reinstalling iTunes resolved the problem
    - Try on another computer/network
    - Wait if it is an Apple problem

  • HT201272 My ipod touch will not update a paid app---Strange Rain. using version 4.2.1. How can I get this installed and updated?

    I have updated to the supposed newest version for my touch.
    But it still will not sync and update my Strange Rain app.
    How can I get this back?

    According to the product description the latest version of this app requires ios 4.3 or later.
    You would have to use your copy of the older version.

  • How can i get my password to update my imac back?

    HOW CAN I GET MY IMAC PASSWORD BACK BECAUSE I DONT REMEMBER IT AND I WANT TO UPDATE IT

    See these for starters. BTW, posting in all caps is considered shouting and frowned upon in these and other forums.

  • How can I get iMovie to automatically save to my external hard drive?

    I am trying to use my external hard drive for iMovie because my movies were cramping up my hard drive. I already moved them and that worked fine. The only problem is that I don't know how to get iMovie to automatically save to the hard drive now. I don't want to have to keep moving the files from my movies folder to the hard drive.

    Do this on the import screen. Look toward the bottom.

  • How can I prevent Firefox from automatically updating?

    Hello,
    I am trying to prevent Firefox 28 from automatically updating to Firefox 29 (on OSX 10.7.5).
    I have the option "Never check for updates" checked under 'Update' in the 'Advanced' Preferences. I have "Automatically update Search Engines" unchecked. I have uninstalled Firefox 29 completely using two separate uninstall clean-up kits and emptied the trash before re-installing Firefox 28... Yet every time I finally re-arrange, customize and re-sync Firefox 28 back to the way I like it, I restart my Mac and Firefox 29 rears it's over-drawn, bubbly, space-wasting, UN-SYNCED, ridiculous tabs on top nonsense user interface.
    I've tried to work with Firefox 29 but the new SYNC simply does not work and that's a deal breaker. I need the changes I make on my mac to be reflected across the other two systems on my desk (one WinXP, one Win7) and vice versa. When I try to sync on FF29 it takes me to a page to log in and then refuses to recognize my email and password (which I have thoroughly confirmed on my other systems as correct).
    Can you please help me prevent Firefox 28 from automatically updating to Firefox 29?

    Thank you for your comments, cor-el.
    Yes, I know about Classic Theme Restorer, but the point is what gives Mozilla the right to update my Firefox when I already have quite clearly set every option to prevent automatic updates?
    I have set:
    app.update.auto - false
    app.update.enabled - false
    app.update.silent - false
    So which secret magic setting has Mozilla used to bypass all these settings and what gives them the right to do it?
    Also, moving the tabs bar and menu bar and whatever else has been moved in Firefox 29 is a THEME change. It is not a security fix. Mozilla should not be in the business of changing the theme or look of Firefox. It is not their business how I want my Firefox to look.
    Regarding "tabs", I have mine down the left side, so this tweaking of the tab bar position is pointless anyway.
    To Mozilla, Just for absolute clarification, there is no way you can possibly justify forcing an update on users computers without their explicit acceptance.
    What if someone found out how Mozilla forced the update? They could then force an update that is NOT a genuine Firefox release and do untold damage to peoples' computers.
    So now I am forced to delete Firefox from my startup script and start it manually just in case their is another forced update that I can stop.
    To cor-el, thank you for your post.
    To Mozilla, you have lost the plot.

  • How can I get the refund of updating to the new OS X Mountain Lion?

    I bought a macbook air in 10th July, after the release of OS X Mountain Lion, I didn't know I can update it for free untill yesterday I read the update policy of the new OS, but unfortunately I had bought the new OS on Appstore, since there wasn't any notification said on Appstore that I can update it free of charge.
    Is that possible I can still get the refund of buying the new OS? How can I do? please help me!

    Welcome to Apple Communities
    http://www.apple.com/support/mac/app-store/contact

Maybe you are looking for

  • Not printing black ink after new ink cartridge installed (HP Officejet Pro L7555)

    I have an HP Officejet Pro L7555 on which I just replaced the black ink cartridge.  Now it won't print in black at all.  I have tried cleaning the printhead multiple times to no avail.  I only get printouts of boxes in all colors except black and not

  • Null Pointer Exception occurs when viewing

    Hi, Can someone tell me how to fix an issue I've got with opening an Oracle database connection via JDev's connection tab (same exception is thrown when configuring either Database or Apps adapter via BPEL designer). I'm using the following: - BPEL D

  • How do email messages end up in the "Important" folder?

    I never created a folder labled "important" so I don't know the rules about how things end up here. I am generally confused as to why thunderbird retains messages in an "all mail" folder when I set up rules to parcel these messages into discrete fold

  • Chapters work in "Simulate" mode, but not on disk

    Hello, I have a project in DVDSP 4.1.2 which was created by someone else, then abandoned at the last minute. Some of the files were missing, so I had to recreate the main movie by re-exporting it from Final Cut Pro to Compressor, then relink it witho

  • Need to CANCEL the SQL statement in TOAD

    Hello All, I have submitted the SQL Query to delete the values from FND_CONCURRENT_REQUESTS table. Later I closed that session. Now above query is making the application very slow. How do I find out that query and cancel it. Please let me know the na