|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2011-11-18 23:48:32
Posts: 139,
Visits: 410
|
|
| Is there a way to tell eco to automatically create an association role when its multiplicity is 1 or greater. I have a a Person (0..1)---- PersonName (1) association. The PersonName is required to be one. It seems like eco should automatically create the PersonName instance whenever a new Person is created. It does not appear to do this. Is there a way to tell eco to create the role automatically? Thanks, Brian
|
|
|
|
|
Junior Member
      
Group: Forum Members
Last Login: 2011-07-24 15:52:35
Posts: 15,
Visits: 190
|
|
| I place the code in the constructor of the main class: public Class1(IEcoServiceProvider serviceProvider) : base(serviceProvider){try { // Place user code ONLY here Class2 class2 = new Class2( serviceProvider ); class2.Class1 = this; } catch (System.Exception) { this.Deinitialize(serviceProvider); throw; } } This enures that a Class2-object is always created and linked when you create a Class1-object.
Regards
Thomas
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2011-07-14 17:05:00
Posts: 290,
Visits: 2 617
|
|
Thomas is correct, it is the right place to perform such a task. ECO has no way of knowing when an associated object should be auto-created or will be assigned by the user from an existing instance.
I just wanted to say that in addition to creating this owned object I often set the SaveAction to Freeze, so that it cannot be removed later.
====
Pete
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2011-11-18 23:48:32
Posts: 139,
Visits: 410
|
|
Thanks for the answers. Eco could add a new "AutoCreate" option on the association that would signal it to create a new instance automatically. Granted the amount of code this would save is minor, but I really like being able to do as much as possible outside of code. Another option would be to automatically create a new association instance whenever the association role is accessed and the value is null. If the association is a 1..1 composition association, I think this would be the preferred behavior. Brian
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2010-08-11 16:02:44
Posts: 338,
Visits: 890
|
|
brian (2008-12-01)
Ecocould add a new "AutoCreate"option on the association that would signal it to create a new instance automatically. Granted the amount of code this would save is minor, but I really like being able to do as much as possible outside of code.
I'd regret this as a feature on the same reason (granted amount of code). ECO should not solve any desire of ours, especialy when it is already easy to do.
But you can use EAL to create new instances within a state machine (self.Association := MyClass.Create).
brian (2008-12-01)
Another option would be to automatically create a new association instance whenever the association role is accessed and the value is null. If the association is a 1..1 composition association, I think this would be the preferred behavior.
Mark association as HasUserCode and create it there.
It's already pretty easy to do.
Cheers.
My Blog: http://dnagir.blogspot.com
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2011-07-14 17:05:00
Posts: 290,
Visits: 2 617
|
|
brian (2008-12-01) Another option would be to automatically create a new association instance whenever the association role is accessed and the value is null. If the association is a 1..1 composition association, I think this would be the preferred behavior.BrianI would strongly advise against you doing this. When you set a property you expect side affects, when you read it you don't. You are introducing a side affect where none would be expected. As a consequence you would have to ensure that anywhere within your application that you read this property you deal with the created object accorindly. 01: Start/Rollback a transaction. This could be a pain because you might already be in a transaction within your business class logic. 02: Start/Undo an undo block. This would be the best option, but is still a lot of work to add just to read an object. Otherwise you'd have to do something like this in the property getter
01: Start undo block 02: Create it 03: UpdateDatabaseWithList(objects in the undo block) This would force you to have to put the embedding in the child object and not the parent object, which isn't always desirable. There are so many reasons you don't want to do this :-)
====
Pete
|
|
|
|
|
Supreme Being
      
Group: Administrators
Last Login: 2010-11-30 12:17:13
Posts: 1 230,
Visits: 1 382
|
|
Peter Morris (2008-12-01)
brian (2008-12-01) Another option would be to automatically create a new association instance whenever the association role is accessed and the value is null. If the association is a 1..1 composition association, I think this would be the preferred behavior.Brian
...
There are so many reasons you don't want to do this :-)
Another is that you may end up with multiple ecospaces trying to create the new object. Suppose that Client1 creates the first object, but never accesses the association. Client 2 and 3 find the object and navigates the association, they will now both create the new object...
You have several options as pointed out already:
* use the constructor and implement in code (my favourite)
* use an effect or entry action on the initial transition in a state machine and implement in EAL.
/Jonas Hogstrom [CapableObjects]
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2011-11-18 23:48:32
Posts: 139,
Visits: 410
|
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2011-07-14 17:05:00
Posts: 290,
Visits: 2 617
|
|
brian (2008-12-02) I'm not so sure I agree that putting code in a contructor that is auto generated by EM is better than having an option in the association to automatically create the object.The main reason that it is better is because it is predictable. You know exactly when that object will get created, whereas with a lazy-create you have no idea at all when the calling program is going to instantiate it, and as a result the calling program needs to know exactly when it can or cannot read that value. You end up not being able to evaluate simple OCL statements such as self.someAssociation.somethingElse without then having to update the database just in case, but you might not be able to update the database yet because the user might be making edits which are not yet valid. You also have the problem that Scot (I think it was) mentioned, two people might create the object at the same time and update the DB. At least within the constructor no two people can create the same object at the same time.
====
Pete
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2011-11-18 23:48:32
Posts: 139,
Visits: 410
|
|
Peter Morris (2008-12-07)
The main reason that it is better is because it is predictable. You know exactly when that object will get created, whereas with a lazy-create you have no idea at all when the calling program is going to instantiate it, and as a result the calling program needs to know exactly when it can or cannot read that value. You end up not being able to evaluate simple OCL statements such as self.someAssociation.somethingElse without then having to update the database just in case, but you might not be able to update the database yet because the user might be making edits which are not yet valid. You also have the problem that Scot (I think it was) mentioned, two people might create the object at the same time and update the DB. At least within the constructor no two people can create the same object at the same time. As I mentioned before I get the lazy-create problems. What I am suggesting is having an option in EM for an association end that determines whether a new object instance is created immediately. Basically does the same thing as putting the code in the constructor. I really don't like adding code in the middle of generated code. A simple option on the EM association end configuration would eliminate the need to add this code. The option could be added to the style comboBox as "Composition - auto create". Regards, Brian
|
|