🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Parsed/Tuple
This page was created by PageReplicator on 2025-09-01. Last edited by PageReplicator on 2025-09-01.

Template:Notice




What is it?[<a href="/index.php?title=Documentation:Tuple&veaction=edit&section=1" class="mw-editsection-visualeditor" title="Edit section: What is it?" data-bs-title="Documentation:Tuple">edit</a> | <a href="/index.php?title=Documentation:Tuple&action=edit&section=1" title="Edit section: What is it?" data-bs-title="Documentation:Tuple">edit source</a>]

Tuple is a fancy word for something “taped together from bits and pieces of other stuff”.

Usage[<a href="/index.php?title=Documentation:Tuple&veaction=edit&section=2" class="mw-editsection-visualeditor" title="Edit section: Usage" data-bs-title="Documentation:Tuple">edit</a> | <a href="/index.php?title=Documentation:Tuple&action=edit&section=2" title="Edit section: Usage" data-bs-title="Documentation:Tuple">edit source</a>]

This is very useful when it comes to building result sets that are not necessarily something that exists in your model - like sums or collecting names and addresses together even if they are stored in different classes. This is similar to an <a target="_blank" rel="nofollow noreferrer noopener" class="external text" href="https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/anonymous-types">Anonymous type</a>

Tuples are what an SQL server returns when you omit the " * " and write explicit stuff in the select part. In fact, the columns in the select part are the tuple definition as far as the SQL server is concerned.

OCL operators that create tuples are:

  • <a href="/Documentation:OCLOperators_groupBy" title="Documentation:OCLOperators groupBy" data-bs-title="Documentation:OCLOperators_groupBy">GroupBy</a>
  • <a href="/Documentation:OCLOperators_collect" title="Documentation:OCLOperators collect" data-bs-title="Documentation:OCLOperators_collect">Collect</a>
Example:[<a href="/index.php?title=Documentation:Tuple&veaction=edit&section=3" class="mw-editsection-visualeditor" title="Edit section: Example:" data-bs-title="Documentation:Tuple">edit</a> | <a href="/index.php?title=Documentation:Tuple&action=edit&section=3" title="Edit section: Example:" data-bs-title="Documentation:Tuple">edit source</a>]
IElement elem = ocl.Evaluate(“Class1.allinstances.class2.class3->groupby(x|x.Attribute1)”);

What do I get back? A Tuple

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

Using Tuples in CodeDress or C# in General[<a href="/index.php?title=Documentation:Tuple&veaction=edit&section=4" class="mw-editsection-visualeditor" title="Edit section: Using Tuples in CodeDress or C# in General" data-bs-title="Documentation:Tuple">edit</a> | <a href="/index.php?title=Documentation:Tuple&action=edit&section=4" title="Edit section: Using Tuples in CodeDress or C# in General" data-bs-title="Documentation:Tuple">edit source</a>]

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

        var onememtuple = (memoryresult[0] as ITuple);
        var onePSCase1tuple = (resultFromSQL92Joins[0] as ITuple);
        var onePSCase2tuple = (resultFromNormalJoins[0] as ITuple);
        for (int i = 0; i < onememtuple.Properties.Count; i++)
        {
          var p = onememtuple.Properties[i];
          var pPS1 = onePSCase1tuple.Properties[i];
          var pPS2 = onePSCase2tuple.Properties[i];
          if (p.AsObject != null)
          {
            Assert.IsTrue(p.AsObject.Equals(pPS1.AsObject), p.StructuralFeature.Name + " differs (sql92joins=true)");
            Assert.IsTrue(p.AsObject.Equals(pPS2.AsObject), p.StructuralFeature.Name + " differs (sql92joins=false)");
          }
        }

Using Tuples in MDriven Designer[<a href="/index.php?title=Documentation:Tuple&veaction=edit&section=5" class="mw-editsection-visualeditor" title="Edit section: Using Tuples in MDriven Designer" data-bs-title="Documentation:Tuple">edit</a> | <a href="/index.php?title=Documentation:Tuple&action=edit&section=5" title="Edit section: Using Tuples in MDriven Designer" data-bs-title="Documentation:Tuple">edit source</a>]

Explanation 1[<a href="/index.php?title=Documentation:Tuple&veaction=edit&section=6" class="mw-editsection-visualeditor" title="Edit section: Explanation 1" data-bs-title="Documentation:Tuple">edit</a> | <a href="/index.php?title=Documentation:Tuple&action=edit&section=6" title="Edit section: Explanation 1" data-bs-title="Documentation:Tuple">edit source</a>]

<a href="/File:2024-06-30_08h01_36.png" class="image" data-bs-title="File:2024-06-30_08h01_36.png" data-bs-filetimestamp="20240630050217"><img alt="Using tuples in mdriven designer" src="/images/thumb/9/9f/2024-06-30_08h01_36.png/362px-2024-06-30_08h01_36.png" decoding="async" width="362" height="302" class="thumbimage" srcset="/images/thumb/9/9f/2024-06-30_08h01_36.png/543px-2024-06-30_08h01_36.png 1.5x, /images/thumb/9/9f/2024-06-30_08h01_36.png/724px-2024-06-30_08h01_36.png 2x" /></a>
<a href="/File:2024-06-30_08h01_36.png" class="internal" title="Enlarge"></a>

Tuples in OCL constitute of Parts and the results are accessed either as a part of the result if Part is derived or computed or as an object type.

To get Category Sales on different dates:

<a href="/File:2024-06-30_08h08_48.png" class="image" data-bs-title="File:2024-06-30_08h08_48.png" data-bs-filetimestamp="20240630055918"><img alt="2024-06-30 08h08 48.png" src="/images/thumb/4/4e/2024-06-30_08h08_48.png/688px-2024-06-30_08h08_48.png" decoding="async" width="688" height="136" class="thumbimage" srcset="/images/thumb/4/4e/2024-06-30_08h08_48.png/1032px-2024-06-30_08h08_48.png 1.5x, /images/thumb/4/4e/2024-06-30_08h08_48.png/1376px-2024-06-30_08h08_48.png 2x" /></a>
<a href="/File:2024-06-30_08h08_48.png" class="internal" title="Enlarge"></a>
<tbody></tbody>
Tuple Parts

(How to access the data)

Description
Part1 Product Category accessed with the name .Category instead of .Part1 since it is a known Type and is not derived.
Part2 The total quantity sold accessed as .Part2 since it is derived.
Part3 Date of Sale accessed as .DateAdded instead of .Part3 since it is a known Type and is not derived.

Explanation 2[<a href="/index.php?title=Documentation:Tuple&veaction=edit&section=7" class="mw-editsection-visualeditor" title="Edit section: Explanation 2" data-bs-title="Documentation:Tuple">edit</a> | <a href="/index.php?title=Documentation:Tuple&action=edit&section=7" title="Edit section: Explanation 2" data-bs-title="Documentation:Tuple">edit source</a>]

To get Product Sales and their percentage of total Sales:

<a href="/File:2024-06-30_08h26_24.png" class="image" data-bs-title="File:2024-06-30_08h26_24.png" data-bs-filetimestamp="20240630060257"><img alt="2024-06-30 08h26 24.png" src="/images/thumb/9/96/2024-06-30_08h26_24.png/780px-2024-06-30_08h26_24.png" decoding="async" width="780" height="196" class="thumbimage" srcset="/images/thumb/9/96/2024-06-30_08h26_24.png/1170px-2024-06-30_08h26_24.png 1.5x, /images/thumb/9/96/2024-06-30_08h26_24.png/1560px-2024-06-30_08h26_24.png 2x" /></a>
<a href="/File:2024-06-30_08h26_24.png" class="internal" title="Enlarge"></a>
<tbody></tbody>
Tuple Parts

(How to access the data)

Description
Part1 Product name as lowercase accessed with name .Part1 instead of .Name since it is derived.
Part2 The total quantity sold accessed as .Part2 since it is derived.
Part3 Sale Percentage of Total Sales accessed with name .Part3 since it is derived.

See also: <a href="/Documentation:OCLOperators_PSEvalTuples" title="Documentation:OCLOperators PSEvalTuples" data-bs-title="Documentation:OCLOperators_PSEvalTuples">PSEvalTuples</a>, <a href="/Documentation:OCLOperators_sqlpassthrough" title="Documentation:OCLOperators sqlpassthrough" data-bs-title="Documentation:OCLOperators_sqlpassthrough">SQLPassthrough</a>




]