Entity looses its changes when casted to IEntity2

Posts   
 
    
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 21-Mar-2007 13:36:21   

I have the following scenario

(1) The UI starts an edit session and each entity the user vists is tracked by a List(Of IEntity2) called EditBuffer.

(2) I inspect the EditBuffer list for dirty entities and collect them in another list


      Dim toReturn As New List(Of IEntity2)()

      'add any entities that were updated
      For Each ent As IEntity2 In Me.EditBuffer
         If ent.IsDirty Then
            toReturn.Add(DirectCast(ent, IEntity2))
         End If
      Next

During debugging I found that the entity added to the toReturn list loses its Dirty flag (becomes FALSE) and the changed fields revert to their values before the change!! Am I taking the wrong approach by casting to IEntity2 or its something else?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Mar-2007 14:20:45   

I don't understand why you use the DirectCast, isn't ent inside the for loop defined as IEntity2? I guess the code should look like the following.

For Each ent As IEntity2 In Me.EditBuffer
         If ent.IsDirty Then
            toReturn.Add(ent)
         End If
     Next

I'm not sure if this is the real cause of your problem, but you can try it out.

omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 21-Mar-2007 14:20:56   

Ok.. my fault flushed instead of holding the changed entities into toRetur, I am holding the buffered un-changed entities..

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Mar-2007 14:25:17   

things like this always happen simple_smile