Tuple
No edit summary
(Automatically adding template at the end of the page.)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
A Tuple is a fancy word for something “taped together from bits and pieces of other stuff”. 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.
Tuple is a fancy word for something “taped together from bits and pieces of other stuff”. 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 [https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/anonymous-types Anonymous type]


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.
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.
Line 7: Line 7:
* [[OCLOperators collect|Collect]]
* [[OCLOperators collect|Collect]]


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


So what do I get back? A Tuple
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.
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:  
The code below shows how to access the tuple result in code:
<pre>
        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)");
          }
        }
</pre>
 
See also [[OCLOperators PSEvalTuples|PSEvalTuples]], [[OCLOperators Sqlpassthrough|SQLPassthrough]]
[[Category:OCLOperators]]
[[Category:OCLOperators]]
{{Edited|July|12|2024}}

Latest revision as of 15:48, 10 February 2024

Tuple is a fancy word for something “taped together from bits and pieces of other stuff”. 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 Anonymous type

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:

Example:

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.

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)");
          }
        }

See also PSEvalTuples, SQLPassthrough

This page was edited 97 days ago on 02/10/2024. What links here