This article was moved to MDriven Wiki Tuple

New from Eco5 is the ability to handle tuples. Tuple is fancy word for something “taped together from bits and pieces of other stuff”. This is very useful when it comes to build result sets that is not necessary something that exists in your model. Like sums or collecting name and address together even if they are stored in different classes.

Tuples are what an sql server return when you omit the “*” and write explicit stuff in the select part. In fact the columns in the select part is the tuple-definition as far as the sql server is concerned.

In Eco 5 OCL operators create tuples: GroupBy and Collect.

Consider this model:


I want to GroupBy the contents of Class3.Attribute1;

IElement elem = ocl.Evaluate(“Class1.allinstances.class2.class3->groupby(x|x.Attribute1)”);

So what do I get back? A Tuple (don’t you just hate rhetoric questions? (I don’t))!

The tuple consists of a type with a generated name and specific properties. The properties are: Attribute1 and List.

The code below shows how to access the tuple result in code:

Code Snippet
  1. private void RenderPrintbands()
  2. {
  3.   IOclService ocl=EcoServiceHelper.GetOclService(_ecoSpace);
  4.   IElement elem = ocl.Evaluate("Class1.allinstances.class2.class3->groupby(x|x.Attribute1)");
  5.   foreach (IElement listelem in elem.GetAsCollection())
  6.   {
  7.     string NameOfTupleResultForGroupedValue = ((listelem as IFeatured).Properties[0]).StructuralFeature.Name;
  8.     string NameOfTupleResultForTheGroupByList = ((listelem as IFeatured).Properties[1]).StructuralFeature.Name;
  10.     foreach (IElement groupedlistelem in (listelem as IFeatured).Properties[NameOfTupleResultForTheGroupByList].GetAsCollection())
  11.     {
  12.       Class3 c3=groupedlistelem.GetValue<Class3>();
  13.     }
  15.   }
  16. }


If I had grouped in more stuff, my tuple would have more properties.

If my tuple property is not an existing “thing” from my model but a tuple in itself it will be named part1 (if I another one, part2 etc).

This entry was posted in Tuples. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.