HI I have a project with uses EF self tracking objects.I am trying to add a relationship to an object . (parentobject.relationshipObject.Add(New relationshipObject...)). But it throws an error:
Cannot change ObservableCollection during a CollectionChanged or PropertyChanged event.
This error occurs in the #Region "Association Fixup" of the code created by the template. Initially the mainobject does not bring any relationship. Only when the item is selected by the user the relationships are updated in the item. i found that if i remove the MainObject from the collection and readd it with the relationships this error does not occur. if i only update the relationship object in the mainObject , this issue occurs when i add a new relationship object from the client side any help is much appreciated
--code sequence is as follows 1. get all the parent entities. 2. when user select an entity get the relationship of the entity and update the relationship entity
parentCol.AsEnumerable.Where(Function(x) x.ID = e.Result.ID).FirstOrDefault().StopTracking() parentCol.AsEnumerable.Where(Function(x) x.ID = e.Result.ID).FirstOrDefault().relationshipEntity = e.Result.relationshipEntity parentCol.AsEnumerable.Where(Function(x) x.ID = e.Result.ID).FirstOrDefault().StartTracking()
- to add a new item in the relationEntity
Dim newRel As New relationshipEntity newRel.Ref_parent_Id = parentItem.ID newRel.REF_rel_ID = relItem.Id parentItem.relationshipEntity.Add(newRel) ---> Throws error here
the relationshipEntity denotes the relationship table between the parent entity and another entity (many to many relationship).
thanks