Implementing a derived association in ECO4

Expand / Collapse
 
     

Implementing a derived association in ECO4


Eco4 introduces automatic subscriptions, so when implementing code derived attributes or associations, there is no need to handle the subscriptions manually any more. Once you have marked the attribute or association as derived in the model and updated your generated code, you should implement a method called "MyAttributeDerive" or "MyAssociationEndDerive". Suppose you have a model with two classes, Person and Project, and a derived association BigProjects between them like this:




The code to derive the BigProjects association end would look like this (add this method to the Person class):

        private object BigProjectsDerive()
        {
            IList<Project> res = new List<Project>();
            foreach (Project p in Projects)
                if (p.Budget > 10000)
                    res.Add(p);
            return res;
        }


User Comments

Click to subscribe to comments RSS feed...

No Member Photo
View Members Profile...,Posted By by throg added den 28 juli 2008


I extended your model...<br /><br />I added a class Worker with a many to many assoc with Project, having WorkersInThisProject assoc end at the Worker end. I then added a derived assoc end called BigProjectsByParticipation (one way nav pointing to Project like yours) with a method added to Person as follows:<br /><br />private object BigProjectsByParticipationDerive()<br />{<br />     IList&lt;Project> res  = new List &lt;Project>();<br />          foreach (Project pgrp in Projects)<br />               if  (pgrp.WorkersInThisProject.Count > 2)<br />                    res.Add(pgrp);<br />               return res; <br />}<br /><br />As I added workers to projects with varying budgets and numbers of workers assigned the appropriate additions were made automatically to the Person autoform tabs for big projects by budgets and participation.<br /><br />What surprised me was how Intellisense picked up the assoc end and made available the Count method. <br /><br />It could be emphasized that the assoc end for the derived method must exactly match the method name Plus the word Derive for the derived assoc to work.<br /><br />Hope this is useful to someone.<br />
<br /><br />
Helpful? YesYes NoNo

No Member Photo
View Members Profile...,Posted By by Jonas Högström added den 12 september 2009
New Member with 3 recognition pointsNew Member with 3 recognition pointsNew Member with 3 recognition pointsNew Member with 3 recognition pointsNew Member with 3 recognition pointsNew Member with 3 recognition pointsNew Member with 3 recognition pointsNew Member with 3 recognition points


In ECO5, the code will look like this:

      partial void BigProjectsDerive(ref List<Project> res)
      {
          res = new List<Project>();
          foreach (Project p in this.Projects)
              if (p.Budget > 10000)
                  res.Add(p);
      }

Helpful? YesYes NoNo

Add Your Comments


Name: *
Email Address:
Web Address:
Verification Code:
*
 

Details
Last Modified:den 7 oktober 2008
Last Modified By: Jonas Högström
Type: HOWTO
Level: Beginner
Article not rated yet.
Article has been viewed 1 306 times.
Options