当前位置: 首页>>代码示例>>C#>>正文


C# Sql.Append方法代码示例

本文整理汇总了C#中Sql.Append方法的典型用法代码示例。如果您正苦于以下问题:C# Sql.Append方法的具体用法?C# Sql.Append怎么用?C# Sql.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sql的用法示例。


在下文中一共展示了Sql.Append方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Can_Get_A_Page_Of_Keys

        public void Can_Get_A_Page_Of_Keys()
        {
            var sql = new Sql();
            sql.Append("SELECT *").Append("FROM [merchInvoice]");

            var page = _db.Page<KeyDto>(1, 10, sql);

            Assert.NotNull(page);
            Assert.AreEqual(15, page.TotalItems);
            Assert.AreEqual(2, page.TotalPages);
        }
开发者ID:Teknyc,项目名称:Merchello,代码行数:11,代码来源:KeyOnlyDtoTests.cs

示例2: GetPaged

        public PagedPeopleResult GetPaged(int itemsPerPage, int pageNumber, string sortColumn,
            string sortOrder, string searchTerm)
        {
            var items = new List<People>();
            var db = DatabaseContext.Database;

            var currentType = typeof(People);

            var query = new Sql().Select("*").From("demo_people");

            if (!string.IsNullOrEmpty(searchTerm))
            {
                int c = 0;
                foreach (var property in currentType.GetProperties())
                {
                    string before = "WHERE";
                    if (c > 0)
                    {
                        before = "OR";
                    }

                    var columnAttri =
                           property.GetCustomAttributes(typeof(ColumnAttribute), false);

                    var columnName = property.Name;
                    if (columnAttri.Any())
                    {
                        columnName = ((ColumnAttribute)columnAttri.FirstOrDefault()).Name;
                    }

                    query.Append(before + " [" + columnName + "] like @0", "%" + searchTerm + "%");
                    c++;
                }
            }
            if (!string.IsNullOrEmpty(sortColumn) && !string.IsNullOrEmpty(sortOrder))
                query.OrderBy(sortColumn + " " + sortOrder);
            else
            {
                query.OrderBy("id asc");
            }

            var p = db.Page<People>(pageNumber, itemsPerPage, query);
            var result = new PagedPeopleResult
            {
                TotalPages = p.TotalPages,
                TotalItems = p.TotalItems,
                ItemsPerPage = p.ItemsPerPage,
                CurrentPage = p.CurrentPage,
                People = p.Items.ToList()
            };
            return result;
        }
开发者ID:Mantus667,项目名称:ListViewForCustomSection,代码行数:52,代码来源:PeopleApiController.cs

示例3: GetPaged

        public UIOMaticPagedResult GetPaged(string typeName, int itemsPerPage, int pageNumber, string sortColumn,
            string sortOrder, string searchTerm)
        {
            var currentType = Type.GetType(typeName);
            var tableName = (TableNameAttribute)Attribute.GetCustomAttribute(currentType, typeof(TableNameAttribute));
            var uioMaticAttri = (UIOMaticAttribute)Attribute.GetCustomAttribute(currentType, typeof(UIOMaticAttribute));

            var db = (Database)DatabaseContext.Database;
            if (!string.IsNullOrEmpty(uioMaticAttri.ConnectionStringName))
                db = new Database(uioMaticAttri.ConnectionStringName);

            var query = new Sql().Select("*").From(tableName.Value);

            EventHandler<QueryEventArgs> tmp = BuildingQuery;
            if (tmp != null)
                tmp(this, new QueryEventArgs(tableName.Value, query));

            if (!string.IsNullOrEmpty(searchTerm))
            {
                int c = 0;
                foreach (var property in currentType.GetProperties())
                {
                    //if (property.PropertyType == typeof (string))
                    //{
                        string before = "WHERE";
                        if (c > 0)
                            before = "OR";

                        var columnAttri =
                           property.GetCustomAttributes().Where(x => x.GetType() == typeof(ColumnAttribute));

                        var columnName = property.Name;
                        if (columnAttri.Any())
                            columnName = ((ColumnAttribute)columnAttri.FirstOrDefault()).Name;

                        query.Append(before + " [" + columnName + "] like @0", "%" + searchTerm + "%");
                        c++;

                    //}
                }
            }
            if (!string.IsNullOrEmpty(sortColumn) && !string.IsNullOrEmpty(sortOrder))
                query.OrderBy(sortColumn + " " + sortOrder);
            else
            {
                var primaryKeyColum = "id";

                var primKeyAttri = currentType.GetCustomAttributes().Where(x => x.GetType() == typeof(PrimaryKeyAttribute));
                if (primKeyAttri.Any())
                    primaryKeyColum = ((PrimaryKeyAttribute)primKeyAttri.First()).Value;

                foreach (var property in currentType.GetProperties())
                {
                    var keyAttri = property.GetCustomAttributes().Where(x => x.GetType() == typeof(PrimaryKeyColumnAttribute));
                    if (keyAttri.Any())
                        primaryKeyColum = property.Name;
                }

                query.OrderBy(primaryKeyColum + " asc");
            }

            EventHandler<QueryEventArgs> temp = BuildedQuery;
            if (temp != null)
                temp(this, new QueryEventArgs(tableName.Value,query));

            var p = db.Page<dynamic>(pageNumber, itemsPerPage, query);
            var result = new UIOMaticPagedResult
            {
                CurrentPage = p.CurrentPage,
                ItemsPerPage = p.ItemsPerPage,
                TotalItems = p.TotalItems,
                TotalPages = p.TotalPages
            };
            var items  = new List<object>();

            foreach (dynamic item in p.Items)
            {
                // get settable public properties of the type
                var props = currentType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                    .Where(x => x.GetSetMethod() != null);

                // create an instance of the type
                var obj = Activator.CreateInstance(currentType);


                // set property values using reflection
                var values = (IDictionary<string, object>)item;
                foreach (var prop in props)
                {
                    var columnAttri =
                           prop.GetCustomAttributes().Where(x => x.GetType() == typeof(ColumnAttribute));

                    var propName = prop.Name;
                    if (columnAttri.Any())
                        propName = ((ColumnAttribute)columnAttri.FirstOrDefault()).Name;

                    if(values.ContainsKey(propName))
                        prop.SetValue(obj, values[propName]);
                }

//.........这里部分代码省略.........
开发者ID:paulsoerensen,项目名称:UIOMatic,代码行数:101,代码来源:PetaPocoObjectController.cs

示例4: GetFiltered

        public IEnumerable<object> GetFiltered(string typeName, string filterColumn, string filterValue, string sortColumn, string sortOrder)
        {
            var currentType = Type.GetType(typeName);
            var tableName = (TableNameAttribute)Attribute.GetCustomAttribute(currentType, typeof(TableNameAttribute));
            var uioMaticAttri = (UIOMaticAttribute)Attribute.GetCustomAttribute(currentType, typeof(UIOMaticAttribute));

            var db = (Database)DatabaseContext.Database;
            if (!string.IsNullOrEmpty(uioMaticAttri.ConnectionStringName))
                db = new Database(uioMaticAttri.ConnectionStringName);

            var query = new Sql().Select("*").From(tableName.Value);

            query.Append("where" + "[" + filterColumn + "] = @0", filterValue);

            if (!string.IsNullOrEmpty(sortColumn) && !string.IsNullOrEmpty(sortOrder))
                query.OrderBy(sortColumn + " " + sortOrder);

            foreach (dynamic item in db.Fetch<dynamic>(query))
            {
                // get settable public properties of the type
                var props = currentType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                    .Where(x => x.GetSetMethod() != null);

                // create an instance of the type
                var obj = Activator.CreateInstance(currentType);


                // set property values using reflection
                var values = (IDictionary<string, object>)item;
                foreach (var prop in props)
                {
                    var columnAttri =
                           prop.GetCustomAttributes().Where(x => x.GetType() == typeof(ColumnAttribute));

                    var propName = prop.Name;
                    if (columnAttri.Any())
                        propName = ((ColumnAttribute)columnAttri.FirstOrDefault()).Name;
                    if (values.ContainsKey(propName))
                        prop.SetValue(obj, values[propName]);
                }

                yield return obj;
            }
        }
开发者ID:paulsoerensen,项目名称:UIOMatic,代码行数:44,代码来源:PetaPocoObjectController.cs

示例5: Append_GivenConsecutiveOrderBys_ShouldBeValid

        public void Append_GivenConsecutiveOrderBys_ShouldBeValid()
        {
            _sql = new Sql()
                .Append("SELECT * FROM blah");

            _sql.Append("ORDER BY x");
            _sql.Append("ORDER BY y");

            _sql.SQL.ShouldBe("SELECT * FROM blah\nORDER BY x\n, y");
        }
开发者ID:kakakakaka1230,项目名称:PetaPoco,代码行数:10,代码来源:SqlTests.cs

示例6: Append_GivenConsecutiveWheres_ShouldBeValid

        public void Append_GivenConsecutiveWheres_ShouldBeValid()
        {
            _sql = new Sql()
                .Append("SELECT * FROM blah");

            _sql.Append("WHERE x");
            _sql.Append("WHERE y");

            _sql.SQL.ShouldBe("SELECT * FROM blah\nWHERE x\nAND y");
        }
开发者ID:kakakakaka1230,项目名称:PetaPoco,代码行数:10,代码来源:SqlTests.cs

示例7: Append_GivenSqLInstance_ShouldBeValid

        public void Append_GivenSqLInstance_ShouldBeValid()
        {
            _sql = new Sql("l0 @0", "a0");
            var sql1 = new Sql("l1 @0", "a1");
            var sql2 = new Sql("l2 @0", "a2");

            _sql.Append(sql1).ShouldBe(_sql);
            _sql.Append(sql2).ShouldBe(_sql);

            _sql.SQL.ShouldBe("l0 @0\nl1 @1\nl2 @2");
            _sql.Arguments.Length.ShouldBe(3);
            _sql.Arguments[0].ShouldBe("a0");
            _sql.Arguments[1].ShouldBe("a1");
            _sql.Arguments[2].ShouldBe("a2");
        }
开发者ID:kakakakaka1230,项目名称:PetaPoco,代码行数:15,代码来源:SqlTests.cs

示例8: StoredProcedureBuilder

 public StoredProcedureBuilder(Sql sql, string procedureName)
 {
     string initalSql = string.Format(PROCEDURE_FORMAT, procedureName);
     _sql = sql.Append(initalSql);
 }
开发者ID:MXPiao,项目名称:NPoco.StoredProcedures,代码行数:5,代码来源:StoredProcedureBuilder.cs

示例9: Append_GivenConsecutiveSetsAndWheres_ShouldBeValid

        public void Append_GivenConsecutiveSetsAndWheres_ShouldBeValid()
        {
            _sql = new Sql()
                .Append("UPDATE blah");

            _sql.Append("SET a = 1");
            _sql.Append("SET b = 2");
            _sql.Append("WHERE x");
            _sql.Append("WHERE y");

            _sql.SQL.ShouldBe("UPDATE blah\nSET a = 1\n, b = 2\nWHERE x\nAND y");
        }
开发者ID:Maxwe11,项目名称:PetaPoco,代码行数:12,代码来源:SqlTests.cs

示例10: Append_GivenConsecutiveSets_ShouldBeValid

        public void Append_GivenConsecutiveSets_ShouldBeValid()
        {
            _sql = new Sql()
                .Append("UPDATE blah");

            _sql.Append("SET a = 1");
            _sql.Append("SET b = 2");

            _sql.SQL.ShouldBe("UPDATE blah\nSET a = 1\n, b = 2");
        }
开发者ID:Maxwe11,项目名称:PetaPoco,代码行数:10,代码来源:SqlTests.cs


注:本文中的Sql.Append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。