Hi
I'll try to subscribe the situation as good as possible.
**DB: **
Department -- Description -- DescriptionValues -- Languages
The above database design gives us the possibility for administrators to translate the description of an department per language. The normal user logged on to our application will only see the description in his language.
Information:
When an entity is saved in our client application, this entitytype and it's PK value is send to a server which broadcasts this to all active client applications. When for example user A adds a new department, the client application of user B will get notified of this. When user B was also using a grid which shows departments, the newly added department of user A will be added automatically. For deletes the entity on user B his departments form will be removed. Now I have a problem for updates for linked entities.
Each department has a code and a description. The code is unique and the description is stored in some linked tables so the description is language independant. When user A changes the description of an department, this is send via the server to user B it's client application. I try to find if the department is found in the collection with departments. If so, I fetch the changed description record (= DescriptionValueEntity). This is correctly fetched from the database. I then want to merge this with the existing entity available in my general context.
List<int> indices = Entities.FindMatches(DepartmentFields.DescriptionId == pInfo.DescriptionId);
if (indices.Count == 1)
{
DescriptionValueEntity newDescription = new DescriptionValueEntity(pInfo.Id);
Main.DataServer.FetchEntity(newDescription);
ISupportsDescriptionTranslation sup = Entities[indices[0]] as ISupportsDescriptionTranslation;
List<int> tmp = sup.Description.DescriptionValues.FindMatches(DescriptionValueFields.Id == pInfo.Id);
if (tmp.Count == 1)
sup.Description.DescriptionValues[tmp[0]] = (DescriptionValueEntity)Main.Context.Get(newDescription);
}
Problem:
Now the problem is with the following line of code
sup.Description.DescriptionValues[tmp[0]] = (DescriptionValueEntity)Main.Context.Get(newDescription);
Before I execute this line of code the DescriptionValues collection contains 4 records (dutch, french, english and polish). From the moment the above line of code is executed, and I want to merge the entity from my context with the entity fetched from the database, that particular entity is removed from my collection and the DescriptionValues collection only contains 3 records any more?
Can you please tell me why things behave like this?
Further I want to state that updates for core entity properties work just fine. So when user A changes the Code of the department (stored in the departmentEntity itself) the entities are nicely merged, and the screen of user B gets updated...
Kind regards,
TomV