This project is read-only.

Issues with remove entities in NModel OOP style

Dec 21, 2008 at 2:45 PM

Hi,

 I have created a model using the LabeledInstance (object-oriented programming in NModel) and I have few issues:

 
1.       An action like RemoveEntity(Entity(1)) doesn't eliminate the entities' elements in the instance field maps even though Entity(1) is removed from the

allEntities static Set field.

 
2.       I get a compiler error when trying the following:

 

[Action]

[Domain("allEmployees")]

void DeleteEmployee()

{ allEmployees = allEmployees.Remove(this); }

 

The compiler error I get:  "Attribute 'Domain' is not valid on this declaration type. It is valid on 'class, param' declarations only".

  

Can you please let me know whether I am doing something wrong?

  

Thank you for your help,

Ofer

Dec 21, 2008 at 9:30 PM

Hi!

[Domain] attribute is meant for action parameters, not actions, thus you get a compiler error. Without further details, the following would be more like what you are after:
 

[Action]

public static void DeleteEmployee([Domain("allEmployees")] emp)

{ allEmployees = allEmployees.Remove(emp); }


Dec 22, 2008 at 8:15 AM

The code snippet I gave above is actually taken from the book "Model Based Software Testing and Analysis with C#" page #251.

Using the code you suggested I can't use "this" and I really hoped that the code in the book would let me do it. In any case I did try to do it the way you suggest and it just doesn't work. It passes compilation but MPV hangs forever without any error message. Is there any log file for MPV where I can look for clues?

I did manage to find a workaround and managed to remove entities from allEntities static Set field:
static Set<Entity> allEntities = Set<Entity>.EmptySet;

But then the removed entities are not being eliminated from the instance field maps. In the State Viewer it looks like the following:
allEntities          Set(Entity(2))
m_ EntityID     Map(Entity(2),"123", Entity(4),"456", Entity(3),"789", Entity(1),"012")

I hoped to have the instance field maps being updated by NModel when I remove entities from the allEntities Set as it is described in the book.

Basically I really wanted to create models the OOP way as suggested in the above book throughout chapter 15 but I failed to do so.
I hope that you will be able to guide me how to go about it.

I really appreciate all your help,
Ofer