Beispiel #1
0
        // basic samples, operators return relations
        static void SampleWithTypes()
        {
            Show("Seq", RelSequenceST.Create(5));
            Show("SP", Supplier.SP);

            var v1 = new RelVarST <TupS>(Supplier.S);
            var v2 = new RelVarST <Tup1>(v1.Value
                                         .Restrict(t => t.Status == 30)
                                         .Rename <TupSX>()   // "SNo", "SName", "Status", "Supplier City"
                                         .Project <Tup1>()); // "Supplier City"

            Show("v2", v2.Value);

            Show("Extend", Supplier.S
                 .Extend <TupSX>(t => "XXX") // "SNo", "SName", "Status", "Supplier City"
                 );

            Show("Join", Supplier.P
                 .Rename <TupPcolour>()               //  "PNo", "PName", "Colour", "Weight", "City"
                 .Restrict(t => t.Colour == "Red")
                 .Project <TupPPno>()                 // "PNo", "PName"
                 .Join <TupSP, TupPjoin>(Supplier.SP) // "PNo", "PName", "SNo", "Qty"
                 );

            Show("Aggregation", Supplier.SP
                 .Aggregate <TupAgg, int>((t, a) => a + t.Qty) //  "PNo", "TotQty"
                 );

            var seed = MMQData.MMQ.Extend <TupMMQA>(t => t.Qty); // "Major", "Minor", "Qty", "AggQty"
            var zmq  = MMQData.MMQ.Rename <TupzMQ>();            // "zmatch", "Minor", "Qty"
            var exp  = seed.While <RelMMQA>(t => t
                                            .Rename <TupMzA>()   // "Major", "zmatch", "ExpQty"
                                            .Join <TupzMQ, TupMMQA>(zmq)
                                            .Transform <TupMMQA>(tt => TupMMQA.Create(tt.Major, tt.Minor, 0, tt.AggQty * tt.Qty)));

            Show("While", exp);
            Show("P1 -> P5", exp
                 .Restrict(t => t.Major == "P1" && t.Minor == "P5")
                 .Aggregate <TupMMT, int>((t, a) => a + t.AggQty));

            v1.Insert(
                RelS.Create <RelS>(
                    new List <TupS> {
                TupS.Create("S6", "White", 25, "Paris"),
                TupS.Create("S7", "Black", 15, "London"),
            })
                );
            Show("Insert P6 P7", v1);

            v1.Update(t => t.City == "Paris", t => TupS.Create(t.SNo, t.SName, t.Status, "Sydney"));
            Show("Move to Sydney", v1);

            v1.Delete(t => t.City == "Sydney");
            Show("Delete Sydneysiders", v1);
        }
Beispiel #2
0
 public static RelSequenceST Create(int count)
 {
     return(RelSequenceST.Create <RelSequenceST>(Enumerable.Range(0, count).Select(n => TupSequenceST.Create(n))));
 }