locked
adding new rows to an observable collection, default foreign key reference from a previous row, change the new row in a bound grid, previous row and new row change RRS feed

  • Question

  •  

    What I think is happening is that multiple MYDATASERVICEUTILGENERATEDCLASS instances in the collection end up referencing the same ForeignKeyObject so when I change the ForeignKeyObject in one instance I actually change it in a number of instances.  Is there a way to copy the ForeignKeyObject before referencing it so that it is unique? 

    I'm doing something like this. 

    Dim
    oNew As New MYDATASERVICEUTILGENERATEDCLASS

    _ADOService.AddToMYDATASERVICEUTILGENERATEDCLASS(oNew)

    'add to service

    oNew.ForeignKeyObject = _myObservableCollection(lastRow).ForeignKeyObject


    _ADOService.SetLink(oNew, "ForeignKeyObject", oNew.ForeignKeyObject)

    _ADOService.UpdateObject(oNew)

    _myObservableCollection.Add(oNew)

    Tuesday, July 28, 2009 12:28 PM

Answers

  • The problem is that the ForeignKeyObject has been associated with an ObservableCollection and so it is being tracked and changed are automatically being propogated.

    If you want a distinct ForeignKeyObject for each MYDATASERVICEUTILGENERATEDCLASS you need to create a new one, set it's properties and then call SetLink.

    Like Emre above I would be interested in what your scenario is to give you proper guidance on solving your issue.

    Thanks,
    Shayne

    Saturday, August 8, 2009 1:52 AM
    Moderator

All replies

  • Hi,

    I don't fully understand the scenario here but the DataServiceContext automatically does identity tracking for you. If you don't want this behaviour you can set MergeOption to NoTracking and the entities you get after each query will be different instances. That being said you can definetely create clones of any of the entities but you will need to handle the merge semantics if you need to persist the changes to the datastore.

    I may be able to help more if you can provide more details on your scenario.

    Thanks,
    Emre
    Thursday, August 6, 2009 3:04 AM
    Answerer
  • The problem is that the ForeignKeyObject has been associated with an ObservableCollection and so it is being tracked and changed are automatically being propogated.

    If you want a distinct ForeignKeyObject for each MYDATASERVICEUTILGENERATEDCLASS you need to create a new one, set it's properties and then call SetLink.

    Like Emre above I would be interested in what your scenario is to give you proper guidance on solving your issue.

    Thanks,
    Shayne

    Saturday, August 8, 2009 1:52 AM
    Moderator