public void AddCustomerList(List<Customer> list)
        {
            const string sql = @"INSERT INTO Customer
            (ID, FirstName, LastName, BirthDay, Height, Weight)
            VALUES (@id,@firstName,@lastName,@birthday,@height,@weight)";

            var cmd = new FluentCommand<string>(sql)
                .AddGuid("id")
                .AddString("firstName")
                .AddString("lastName")
                .AddDateTime("birthday")
                .AddDecimal("height")
                .AddInt("weight");

            foreach (var customer in list)
            {
                customer.ID = Guid.NewGuid();
                cmd.AsNonQuery(customer.ID,
                    customer.FirstName,
                    customer.LastName,
                    customer.Birthday,
                    customer.Height,
                    customer.Weight);
            }
        }
Exemple #2
0
        public void FluentExecute()
        {
            var cmd = new FluentCommand<string>("WithOutParams")
                .SetCommandType(CommandType.StoredProcedure)
                .Add("out1", 9).SetDirection(ParameterDirection.InputOutput)
                .Add("out2", 9).SetDirection(ParameterDirection.InputOutput);
            cmd.AsNonQuery();

            Console.WriteLine(cmd.GetParamValue("out1"));
            Console.WriteLine(cmd.GetParamValue("out2"));
        }
        protected override void FormatExpandSelectOrderby(IList<string> commandClauses, EntityCollection resultCollection, FluentCommand command)
        {
            if (command.Details.ExpandAssociations.Any())
            {
                commandClauses.Add(string.Format("{0}={1}", ODataLiteral.Expand,
                    string.Join(",", command.Details.ExpandAssociations.Select(x =>
                        FormatExpansionSegment(x.Key, resultCollection,
                        x.Value,
                        SelectExpansionSegmentColumns(command.Details.SelectColumns, x.Key),
                        SelectExpansionSegmentColumns(command.Details.OrderbyColumns, x.Key))))));
            }

            FormatClause(commandClauses, resultCollection, 
                SelectExpansionSegmentColumns(command.Details.SelectColumns, null), 
                ODataLiteral.Select, FormatSelectItem);

            FormatClause(commandClauses, resultCollection, 
                SelectExpansionSegmentColumns(command.Details.OrderbyColumns, null), 
                ODataLiteral.OrderBy, FormatOrderByItem);
        }
        public void FluentCommandKeepAlive()
        {
            using (FluentCommand<int> cmd = new FluentCommand<int>(_sql))
            {
                cmd.AddInt("id")
                    .AddString("code", 15)
                    .AddString("name", 255)
                    .AddString("mft", 56)
                    .AddString("size")
                    .AddBoolean("discontinued")
                    .AddString("barcode", 56);

                for (int i = 0; i < _productList.Count; i++)
                {
                    var product = _productList[i];
                    cmd.AsNonQuery(
                        product.ID, product.ProductCode, product.Name, product.Manufacturer, product.Size,
                        !product.Active, product.ProductCode
                        );
                }
            }
        }
        public void FluentCommandKeepAliveWithTransaction()
        {
            var conn = ConnectionFactory.GetConnection();
            using (var trans = conn.BeginTransaction())
            {
                using (FluentCommand<int> cmd = new FluentCommand<int>(_sql, conn))
                {
                    cmd.SetTransaction(trans)
                        .AddInt("id")
                        .AddString("code", 15)
                        .AddString("name", 255)
                        .AddString("mft", 56)
                        .AddString("size")
                        .AddBoolean("discontinued")
                        .AddString("barcode", 56);

                    for (int i = 0; i < _productList.Count; i++)
                    {
                        var product = _productList[i];
                        cmd.AsNonQuery(
                            product.ID, product.ProductCode, product.Name, product.Manufacturer, product.Size,
                            !product.Active, product.ProductCode);
                    }
                }
                trans.Commit();
            }
        }
        public IList<Customer> GetList()
        {
            const string sql =
                @"SELECT ID, FirstName, LastName, BirthDay, Height, Weight
            FROM Customer";
            int i = 0;

            var list = new FluentCommand<Customer>(sql)
                .SetMap(reader => new Customer
                                  {
                                      ID = reader.GetGuid("ID"),
                                      FirstName = reader.GetString("FirstName"),
                                      LastName = reader.GetString("LastName"),
                                      Birthday = reader.GetDateTime("Birthday"),
                                      Height = reader.GetIntNullable("Height"),
                                      Weight = reader.GetIntNullable("Weight")
                                  })
                .AsList();

            return list;
        }
 protected override void FormatExpandSelectOrderby(IList<string> commandClauses, EntityCollection resultCollection, FluentCommand command)
 {
     FormatClause(commandClauses, resultCollection, command.Details.ExpandAssociations, ODataLiteral.Expand, FormatExpandItem);
     FormatClause(commandClauses, resultCollection, command.Details.SelectColumns, ODataLiteral.Select, FormatSelectItem);
     FormatClause(commandClauses, resultCollection, command.Details.OrderbyColumns, ODataLiteral.OrderBy, FormatOrderByItem);
 }
        protected override void FormatExpandSelectOrderby(IList <string> commandClauses, EntityCollection resultCollection, FluentCommand command)
        {
            if (command.Details.ExpandAssociations.Any())
            {
                var formattedExpand = string.Join(",", command.Details.ExpandAssociations.Select(x =>
                                                                                                 FormatExpansionSegment(x.Key, resultCollection,
                                                                                                                        x.Value,
                                                                                                                        SelectPathSegmentColumns(command.Details.SelectColumns, x.Key),
                                                                                                                        SelectPathSegmentColumns(command.Details.OrderbyColumns, x.Key))));
                commandClauses.Add($"{ODataLiteral.Expand}={formattedExpand}");
            }

            FormatClause(commandClauses, resultCollection,
                         SelectPathSegmentColumns(command.Details.SelectColumns, null,
                                                  command.Details.ExpandAssociations.Select(FormatFirstSegment).ToList()),
                         ODataLiteral.Select, FormatSelectItem);

            FormatClause(commandClauses, resultCollection,
                         command.Details.OrderbyColumns
                         .Where(o => !command.Details.ExpandAssociations.Select(ea => ea.Key)
                                .Any(ea => IsInnerCollectionOrderBy(ea, resultCollection, o.Key))).ToList(),
                         ODataLiteral.OrderBy, FormatOrderByItem);
        }
Exemple #9
0
 protected BoundClient <U> Link <U>(FluentCommand command, ODataExpression expression)
     where U : class
 {
     return(Link <U>(command, expression.Reference));
 }
 protected override void FormatExpandSelectOrderby(IList <string> commandClauses, EntityCollection resultCollection, FluentCommand command)
 {
     FormatClause(commandClauses, resultCollection, command.Details.ExpandAssociations, ODataLiteral.Expand, FormatExpandItem);
     FormatClause(commandClauses, resultCollection, command.Details.SelectColumns, ODataLiteral.Select, FormatSelectItem);
     FormatClause(commandClauses, resultCollection, command.Details.OrderbyColumns, ODataLiteral.OrderBy, FormatOrderByItem);
 }
        protected override void FormatExpandSelectOrderby(IList <string> commandClauses, EntityCollection resultCollection, FluentCommand command)
        {
            if (command.Details.ExpandAssociations.Any())
            {
                commandClauses.Add(string.Format("{0}={1}", ODataLiteral.Expand,
                                                 string.Join(",", command.Details.ExpandAssociations.Select(x =>
                                                                                                            FormatExpansionSegment(x.Key, resultCollection,
                                                                                                                                   x.Value,
                                                                                                                                   SelectExpansionSegmentColumns(command.Details.SelectColumns, x.Key),
                                                                                                                                   SelectExpansionSegmentColumns(command.Details.OrderbyColumns, x.Key))))));
            }

            FormatClause(commandClauses, resultCollection,
                         SelectExpansionSegmentColumns(command.Details.SelectColumns, null),
                         ODataLiteral.Select, FormatSelectItem);

            FormatClause(commandClauses, resultCollection,
                         SelectExpansionSegmentColumns(command.Details.OrderbyColumns, null),
                         ODataLiteral.OrderBy, FormatOrderByItem);
        }