Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Viking on October 16, 2020, 06:36:10 am

Title: Transient change of values
Post by: Viking on October 16, 2020, 06:36:10 am
Hi,

I renamed a TaggedValue via script (C#). The debugger shows that I renamed the TV. That’s fine. If I ask the TV in another method for its name (myTV.Name), it shows the original name. That’s not fine. I did not perform myElement.TaggedValues a second time. I am still working with the same collection.

I do not want to update() the TV because I do not want to update the database. So I was trying to clone the TVs. Not possible.

Did I do something wrong? Is it not possible to change the value? When does it get overwritten? By each method call? V.
Title: Re: Transient change of values
Post by: qwerty on October 16, 2020, 07:42:49 am
Wash me but don't make we wet? I don't get what you try to achieve.

q.

P.S. I think Uffe got it, but if you had included a piece of code it would have been easier to spot that.
Title: Re: Transient change of values
Post by: Uffe on October 17, 2020, 05:20:44 pm
Hello,

Did I do something wrong? Is it not possible to change the value? When does it get overwritten? By each method call?

That isn't documented. The in-memory copy certainly gets updated when you call Update() (writing the changes to the database) or Refresh() (re-reading the data from the database).

But I seem to recall that you can make changes to a simple ojbect (meaning no Collections involved) and then look at them before Update():ing. You mention that you are working with the same Collection, and that might be the problem: the Collection hasn't been updated, so if you ask it for member number 5 again, it'll return what was in there before. Try passing the individual TaggedValue to your sub-method instead.

HTH,


/Uffe

Title: Re: Transient change of values
Post by: Viking on October 17, 2020, 07:58:27 pm
Hello,
Did I do something wrong? Is it not possible to change the value? When does it get overwritten? By each method call?
That isn't documented. The in-memory copy certainly gets updated when you call Update() (writing the changes to the database) or Refresh() (re-reading the data from the database).
But I seem to recall that you can make changes to a simple ojbect (meaning no Collections involved) and then look at them before Update():ing. You mention that you are working with the same Collection, and that might be the problem: the Collection hasn't been updated, so if you ask it for member number 5 again, it'll return what was in there before. Try passing the individual TaggedValue to your sub-method instead.
HTH,
/Uffe

Many thanks @Uffe.

I updated the object as part of the collection and did not use update() or refresh(). Normally that should work. EA-OM is different at this point.

I have to pass a collection. But if I understood you correctly I just have to create a new List. I will try this.
Title: Re: Transient change of values
Post by: Geert Bellekens on October 18, 2020, 12:32:42 am
EA.Collections are not your run-of the mill collection.
They might even query the database when iterating.

If you need a list of elements, iterate collection only once and store the items in a "normal" collection object (.Net List<T> or similar), and the pass on that collection;

Geert
Title: Re: Transient change of values
Post by: Viking on October 18, 2020, 12:50:01 am
EA.Collections are not your run-of the mill collection.
They might even query the database when iterating.
If you need a list of elements, iterate collection only once and store the items in a "normal" collection object (.Net List<T> or similar), and the pass on that collection;
Geert

"They might even query the database when iterating." That must be the reason. Thank you, @Geert.