Book a Demo

Author Topic: Transient change of values  (Read 5060 times)

Viking

  • EA User
  • **
  • Posts: 477
  • Karma: +2/-2
    • View Profile
Transient change of values
« 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.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Transient change of values
« Reply #1 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.
« Last Edit: October 17, 2020, 06:46:18 pm by qwerty »

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Transient change of values
« Reply #2 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

My theories are always correct, just apply them to the right reality.

Viking

  • EA User
  • **
  • Posts: 477
  • Karma: +2/-2
    • View Profile
Re: Transient change of values
« Reply #3 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.
« Last Edit: October 17, 2020, 08:01:54 pm by Viking »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13510
  • Karma: +573/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Transient change of values
« Reply #4 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

Viking

  • EA User
  • **
  • Posts: 477
  • Karma: +2/-2
    • View Profile
Re: Transient change of values
« Reply #5 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.