No edit summary |
No edit summary |
||
(29 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
<message>Provide more explanation on how to use Tuples. </message> | |||
Tuples are what an SQL server returns when you omit the | ==== What is it? ==== | ||
Tuple is a fancy word for something “taped together from bits and pieces of other stuff”. | |||
==== Usage ==== | |||
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. | |||
OCL operators that create tuples are: | OCL operators that create tuples are: | ||
* [[OCLOperators groupBy|GroupBy]] | * [[Documentation:OCLOperators groupBy|GroupBy]] | ||
* [[OCLOperators collect|Collect]] | * [[Documentation:OCLOperators collect|Collect]] | ||
===== Example: ===== | |||
IElement elem = ocl.Evaluate(“Class1.allinstances.class2.class3->groupby(x|x.Attribute1)”); | |||
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. | ||
==== Using Tuples in CodeDress or C# in General ==== | |||
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> | |||
== Using Tuples in MDriven Designer == | |||
=== Explanation 1 === | |||
[[File:2024-06-30 08h01 36.png|alt=Using tuples in mdriven designer|none|thumb|362x362px]] | |||
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: | |||
[[Category:OCLOperators]] | [[Category:OCLOperators]] | ||
[[File:2024-06-30 08h08 48.png|none|thumb|688x688px]] | |||
{| class="wikitable" | |||
!Tuple Parts | |||
(How to access the data) | |||
!Description | |||
|- | |||
|Part1 | |||
|Product Category accessed with the name <code><span class="col-black">'''.Category'''</span></code> instead of <code><span class="col-black">'''.Part1'''</span></code> since it is a known Type and is not derived. | |||
|- | |||
|Part2 | |||
|The total quantity sold accessed as <code><span class="col-black">'''.Part2'''</span></code> since it is derived. | |||
|- | |||
|Part3 | |||
|Date of Sale accessed as <code><span class="col-black">'''.DateAdded'''</span></code> instead of <code><span class="col-black">'''.Part3'''</span></code> since it is a known Type and is not derived. | |||
|} | |||
=== Explanation 2 === | |||
To get '''Product Sales''' and their percentage of total Sales: | |||
[[File:2024-06-30 08h26 24.png|none|thumb|780x780px]] | |||
{| class="wikitable" | |||
!Tuple Parts | |||
(How to access the data) | |||
!Description | |||
|- | |||
|Part1 | |||
|Product name as lowercase accessed with name <code><span class="col-black">'''.Part1'''</span></code> instead of <code><span class="col-black">'''.Name'''</span></code> since it is derived. | |||
|- | |||
|Part2 | |||
|The total quantity sold accessed as <code><span class="col-black">'''.Part2'''</span></code> since it is derived. | |||
|- | |||
|Part3 | |||
|Sale Percentage of Total Sales accessed with name <code><span class="col-black">'''.Part3'''</span></code> since it is derived. | |||
|} | |||
'''See also:''' [[Documentation:OCLOperators PSEvalTuples|PSEvalTuples]], [[Documentation:OCLOperators sqlpassthrough|SQLPassthrough]] | |||
[[Category:OCLOperators]] | |||
{{Edited|July|12|2025}} | |||
[[Category:TOC]] |
Latest revision as of 05:06, 11 February 2025
What is it?
Tuple is a fancy word for something “taped together from bits and pieces of other stuff”.
Usage
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.
Using Tuples in CodeDress or C# in General
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
Explanation 1
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:
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
To get Product Sales and their percentage of total Sales:
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: PSEvalTuples, SQLPassthrough