none
Save specific object RRS feed

  • Question

  • I'm trying to save a specific object to the OData service. The only way I can find to do so is to use DataServiceContext.SaveChanges, but that saves all changed objects, which is not what I'm trying to do..

    Any ideas on how to solve my issue?

    Friday, February 22, 2013 12:55 PM

Answers

  • The DataServiceCollection<> has build in (implicit) change tracking, so if you are using the DataServiceCollection<> to collect data - change tracking is implicit.

    If you wish to keep Window1 and 2 separated - you could consider having two DataServiceContext's one for Window1 and the other for Window2 and calling SaveChanges() on the correct one.

    Regards

    Uffe

    Thursday, February 28, 2013 12:51 PM

All replies

  • Hi Matthijs,

    Welcome to the MSDN forum.

    I am trying to involve another expert into your thread. please wait for the response. Sorry for any inconvenience.

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 25, 2013 7:46 AM
  • Hey Matthijis,

    The only way to save one object is just to have only one object that is tracked by the change tracking prior to calling save changes. So if you don't call context.AddObject, or any of the other tracking methods for the other objects they will not be included.

    What is the scenario around saving just one entity?

    Thanks,

    Chris Robinson - WCF Data Services


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, February 26, 2013 10:39 PM
    Moderator
  • I have multiple windows/forms in a MDI kind of way. Now if window 1 gets saved, window 2 shouldn't get saved yet.

    It seems that change tracking of retrieved objects is not implicit. Is that correct? If so, that would solve my problem. :)

    Wednesday, February 27, 2013 4:27 PM
  • The DataServiceCollection<> has build in (implicit) change tracking, so if you are using the DataServiceCollection<> to collect data - change tracking is implicit.

    If you wish to keep Window1 and 2 separated - you could consider having two DataServiceContext's one for Window1 and the other for Window2 and calling SaveChanges() on the correct one.

    Regards

    Uffe

    Thursday, February 28, 2013 12:51 PM
  • I definitely agree, I believe two different context's is the best way to do this.

    Thanks,

    Chris Robinson - WCF Data Services


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, February 28, 2013 4:24 PM
    Moderator