コード例 #1
0
        public void NestedSelectMappingTest()
        {
            QueryDefinition nestedSelectMapping = Define.QueryResult("select id as cid, sname,'2017-03-01' as LastUpdate, fname, BDAY, ADR_STREET, ADR_CITY from customer",
                                                                     new
            {
                Id         = Define.Column("cid"),
                SName      = Define.Column(),
                Age        = 22,
                LastUpdate = Define.Column(),
                Birthday   = Define.Column("BDAY"),
                Address    = new
                {
                    Street = Define.Column("ADR_STREET"),
                    City   = Define.Column("ADR_CITY"),
                },
                Invoices = Define.QueryResult("select id as iid, inv_date, amount from invoices where customer_id=${column:cid} and amount > ${context:min_amount}",
                                              new
                {
                    InvoiceId   = Define.Column("iid"),
                    Inv_Date    = Define.Column(),
                    TotalAmount = Define.Column("amount"),
                }
                                              ),
                Orders = Define.QueryResult("select id as oid, article from orders where customer_id=${column:cid}",
                                            new
                {
                    OrderId     = Define.Column("oid"),
                    ArticleName = Define.Column("article"),
                }
                                            )
            });

            var compiledMapping = nestedSelectMapping.Compile();

            // Execute Mapping
            DoInConnection((connection) =>
            {
                using (var engine = new MappingEngine(connection, compiledMapping))
                {
                    using (var ms = new MemoryStream())
                    {
                        var context = new Dictionary <string, object>();
                        context.Add("min_amount", 100);
                        engine.ExecuteMapping(ms, context, false);
                        var json = System.Text.Encoding.UTF8.GetString(ms.ToArray());
                        Assert.Equal(nestedSelectGeneratedJson, json);
                    }
                }
            }
                           );
        }