EntityState not getting updated when I update an EntityReference

Last post 06-09-2009 8:33 AM by mpaterson. 4 replies.

Sort Posts:

  • EntityState not getting updated when I update an EntityReference

    06-08-2009, 10:52 PM
    • Contributor
      4,575 point Contributor
    • mpaterson
    • Member since 11-26-2006, 10:24 PM
    • Ipswich, MA
    • Posts 1,298

    I have an object Person with an EntityReference.
    I expected that when I modified the value of the entityReference that the EntityState of the Person EntityObject would be updated to Modified.
    However, this isn't happening.
    The EntityState is staying Unchanged.

    Does anyone know what the deal is?

     

    Thanks

    If everything happens for a reason what is the reason for this error?
  • Re: EntityState not getting updated when I update an EntityReference

    06-09-2009, 1:23 AM

    Are u loading the object by primary key (or some other unique comuln) and then settnig the values? as first u have to load the single entity colletion before calling update.. also can u tell me if u are updating entire collection or a single entity..

    check out following sample for single entity update,.  

     int defImageID = Convert.ToInt32(hotelImageColl[0].NImageID);

    newImage = new Images();
    newImage.LoadByPrimaryKey(defImageID);//Here i Load the collection to be updated
    newImage.CImageTitle = txtDefaultImageTitle.Text.Trim();
    newImage.Save();

    Please mark this post as Answer if it is of help to you!

    " Every wall is a door..! "
  • Re: EntityState not getting updated when I update an EntityReference

    06-09-2009, 7:40 AM
    Answer
    • Contributor
      2,397 point Contributor
    • maverickhyd
    • Member since 03-25-2009, 6:38 AM
    • Posts 416
  • Re: EntityState not getting updated when I update an EntityReference

    06-09-2009, 8:30 AM
    • Contributor
      4,575 point Contributor
    • mpaterson
    • Member since 11-26-2006, 10:24 PM
    • Ipswich, MA
    • Posts 1,298
    Thanks for the link. It is hugely helpful. I did find another way to do it but I will definitely look into the AssociationChanged event to raise OnPropertyChanged.
    If everything happens for a reason what is the reason for this error?
  • Re: EntityState not getting updated when I update an EntityReference

    06-09-2009, 8:33 AM
    • Contributor
      4,575 point Contributor
    • mpaterson
    • Member since 11-26-2006, 10:24 PM
    • Ipswich, MA
    • Posts 1,298

     Kavita,

     I'm using the exposed property for the EntityReference (although I'm sure the same thing would happen for EntityCollections) to set the reference to a new instance of the object.

    Ie. Person.Address = aAddress;

    What I found through a good deal of reading was that the EntityState of Person isn't updated but the Relationship between Person and Address objects is updated.

    If everything happens for a reason what is the reason for this error?
Page 1 of 1 (5 items)