Call to SetEntitySyncInformation is causing entity to be marked dirty

Posts   
 
    
Kirk
User
Posts: 22
Joined: 26-Apr-2004
# Posted on: 21-Apr-2006 00:07:49   

The following generated code causes the entity to be marked dirty. This happens when an EntityCollection is bound to an UltraGrid. The collection is empty when bound. The field that is changed is LocationId which I believe is somehow set when the last statement is executed. It is 0 and IsChanged is false before last statement is executed, but is 3 and IsChanged is true after the last statement is executed.


private void SetupSyncSpecimenCollectionLocation(IEntity2 relatedEntity)
{
DesetupSyncSpecimenCollectionLocation(true);
if(relatedEntity!=null)
{
_specimenCollectionLocation = (SpecimenCollectionLocationEntity)relatedEntity;
_specimenCollectionLocation.ActiveContext = base.ActiveContext;
_specimenCollectionLocation.AfterSave+=new EventHandler(OnEntityAfterSave);
base.SetEntitySyncInformation("SpecimenCollectionLocation", _specimenCollectionLocation, CollectionLocationContactEntity.Relations.SpecimenCollectionLocationEntityUsingLocationId);
}
}

The reason I noticed this is that a template row is created and if I tab through it, it actually adds an entity to the collection. If I check for entity.IsNew and entity.IsDirty, I can filter these from being saved. Since I have not edited this entity at all I was wondering why it is marked IsDirty.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Apr-2006 08:41:00   

SetupSyncSpecimenCollectionLocation() is called when a related entity (SpecimenCollectionLocationEntity) is associated with your main entity (CollectionLocationContact).

This makes the main entity dirty (changed).

Let's assume you have 2 Tables A & B

A

ID (PK) Name BID (FK)

B

ID (PK) Name

now when you Associate B to A -> a.B = b -> which calls the A.SetupSyncB() method This sets the a.BID = b.ID -> making the a instance dirty (changed) So if a is saved (Inserted or Updated) the BID field is saved with the new value.