Cant update Navigation Propery RRS feed

  • Question

  • Hi guys,

    I have been battling for hours on this problem. I have a model like below

    All my tables have a Primary Key field. The realation between Guest and AccommodationSet is defined in the database and so in the model.

    No matter if I load up a enitity in the same Context and try replace the value of Guest on the AccommodationSet, I get a Error.
    I also get the same error if I simply try change the GuestID property on the AccommodationSet.

    Context.Load(Context.LoadGuestForGuestSwopQuery(NewGuestID), lo =>
                                    TheOppertunity.Guest = lo.Entities.First();

    Or this simple one liner

    TheOppertunity.GuestID = NewGuestID;

    Both times I get a error about, cannot change the property ID as it is the objects key information.

    I am not trying to create another entity in the DB. I simply have a different existing guest who I would like to "become the owner" of the accommodation set.
    I cannot understand what is going wrong at all. Any help will be great.



    • Moved by Alexander Sun Wednesday, September 5, 2012 2:54 AM EF related (From:LINQ to SQL)
    Monday, September 3, 2012 8:26 PM

All replies

  • Hi Louis,

    Welcome to the MSDN forum.

    Could you please let me know what the “TheOppertunity” is? A AccommodationSet object?

    Please take a look at this page which I think is helpful for you: http://stackoverflow.com/questions/3187963/the-property-id-is-part-of-the-objects-key-information-and-cannot-be-modified

    Good day.

    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, September 5, 2012 3:02 AM
  • Hi Alexnder,

    I found the problem late last night. Somehow the System.Windows.Dll was set to copy local.
    I have no idea how this happened. Once I set that option to false all was well.

    I have seen this kind of problem before though with the System.Dll copy local set to true.
    Is there a reason why when they are set to true, that we get this error on entity where we try change a FK value?

    Is there a way we can detect these kind of things when the server starts up so we can know straight away that it is wrong?
    I am using this in a Silverlight project.

    The Oppertunity is also a table in the model.



    Wednesday, September 5, 2012 1:05 PM
  • Hi Louis,

    Did you mean this problem happened before copy local was set to true?

    Or you mean it worked normally before the copy local was set to true?

    If the TheOppertunity has the Guest type navigation property, please use this instead:

    TheOppertunity.Guest = NewGuestIDObj;

    Good day.

    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, September 6, 2012 6:12 AM