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


C# SelectSqlBuilder.From方法代码示例

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


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

示例1: FromThrowsArgumentExceptionForEmptyTableName

        public void FromThrowsArgumentExceptionForEmptyTableName()
        {
            var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty);

            var exception = Assert.Throws<ArgumentException>(
                () => sqlBuilder.From(""));

            Assert.Equal(ExceptionMessages.ArgumentNullOrEmpty.FormatWith("table"), exception.Message);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:9,代码来源:SelectSqlBuilderTests.cs

示例2: SelectFromType

        public void SelectFromType()
        {
            var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty);

            var sqlQuery = sqlBuilder
                .From(typeof(Customer))
                .ToSqlQuery();

            Assert.Equal("SELECT Created,CreditLimit,DateOfBirth,Id,Name,CustomerStatusId,Updated,Website FROM Sales.Customers", sqlQuery.CommandText);
            Assert.Empty(sqlQuery.Arguments);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:11,代码来源:SelectSqlBuilderTests.cs

示例3: SelectFromWhereComplex

        public void SelectFromWhereComplex()
        {
            var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "Column1", "Column2", "Column3");

            var sqlQuery = sqlBuilder
                .From("Table")
                .Where("Column1 = @p0 OR @p0 IS NULL", "Foo")
                .AndWhere("Column2 BETWEEN @p0 AND @p1", DateTime.Today.AddDays(-1), DateTime.Today)
                .OrWhere("Column3 IN (@p0, @p1, @p2, @p3)", 1, 2, 3, 4)
                .ToSqlQuery();

            Assert.Equal("SELECT Column1,Column2,Column3 FROM Table WHERE (Column1 = @p0 OR @p0 IS NULL) AND (Column2 BETWEEN @p1 AND @p2) OR (Column3 IN (@p3, @p4, @p5, @p6))", sqlQuery.CommandText);

            Assert.Equal(7, sqlQuery.Arguments.Count);

            Assert.Equal(DbType.String, sqlQuery.Arguments[0].DbType);
            Assert.Equal("Foo", sqlQuery.Arguments[0].Value);

            Assert.Equal(DbType.DateTime, sqlQuery.Arguments[1].DbType);
            Assert.Equal(DateTime.Today.AddDays(-1), sqlQuery.Arguments[1].Value);

            Assert.Equal(DbType.DateTime, sqlQuery.Arguments[2].DbType);
            Assert.Equal(DateTime.Today, sqlQuery.Arguments[2].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[3].DbType);
            Assert.Equal(1, sqlQuery.Arguments[3].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[4].DbType);
            Assert.Equal(2, sqlQuery.Arguments[4].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[5].DbType);
            Assert.Equal(3, sqlQuery.Arguments[5].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[6].DbType);
            Assert.Equal(4, sqlQuery.Arguments[6].Value);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:36,代码来源:SelectSqlBuilderTests.cs

示例4: SelectFromSpecifyingColumnsAndTableName

        public void SelectFromSpecifyingColumnsAndTableName()
        {
            var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "Column1", "Column2");

            var sqlQuery = sqlBuilder
                .From("Table")
                .ToSqlQuery();

            Assert.Equal("SELECT Column1,Column2 FROM Table", sqlQuery.CommandText);
            Assert.Empty(sqlQuery.Arguments);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:11,代码来源:SelectSqlBuilderTests.cs

示例5: SelectFromSpecifyingColumnsAndType

        public void SelectFromSpecifyingColumnsAndType()
        {
            var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "Name", "DateOfBirth");

            var sqlQuery = sqlBuilder
                .From(typeof(Customer))
                .ToSqlQuery();

            Assert.Equal("SELECT Name,DateOfBirth FROM Sales.Customers", sqlQuery.CommandText);
            Assert.Empty(sqlQuery.Arguments);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:11,代码来源:SelectSqlBuilderTests.cs

示例6: OrderByDescendingAppendsColumnsCorrectlyForSingleColumn

        public void OrderByDescendingAppendsColumnsCorrectlyForSingleColumn()
        {
            var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "CustomerId");

            var sqlQuery = sqlBuilder.From("Customer")
                .OrderByDescending("CustomerId")
                .ToSqlQuery();

            Assert.Equal("SELECT CustomerId FROM Customer ORDER BY CustomerId DESC", sqlQuery.CommandText);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:10,代码来源:SelectSqlBuilderTests.cs

示例7: SelectFromOrderByDescendingThenAscending

        public void SelectFromOrderByDescendingThenAscending()
        {
            var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "Column1", "Column2");

            var sqlQuery = sqlBuilder
                .From("Table")
                .OrderByDescending("Column1")
                .OrderByAscending("Column2")
                .ToSqlQuery();

            Assert.Equal("SELECT Column1,Column2 FROM Table ORDER BY Column1 DESC,Column2 ASC", sqlQuery.CommandText);
            Assert.Empty(sqlQuery.Arguments);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:13,代码来源:SelectSqlBuilderTests.cs

示例8: SelectWhereOrWhereInArgs

        public void SelectWhereOrWhereInArgs()
        {
            var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "Column1");

            var sqlQuery = sqlBuilder
                .From("Table")
                .Where("Column2").IsEqualTo("FOO")
                .OrWhere("Column1").In(1, 2, 3)
                .ToSqlQuery();

            Assert.Equal("SELECT Column1 FROM Table WHERE (Column2 = ?) OR (Column1 IN (?,?,?))", sqlQuery.CommandText);

            Assert.Equal(4, sqlQuery.Arguments.Count);

            Assert.Equal(DbType.String, sqlQuery.Arguments[0].DbType);
            Assert.Equal("FOO", sqlQuery.Arguments[0].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[1].DbType);
            Assert.Equal(1, sqlQuery.Arguments[1].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[2].DbType);
            Assert.Equal(2, sqlQuery.Arguments[2].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[3].DbType);
            Assert.Equal(3, sqlQuery.Arguments[3].Value);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:26,代码来源:SelectSqlBuilderTests.cs

示例9: SelectWhereOrWhereInArgsWithSqlCharacters

        public void SelectWhereOrWhereInArgsWithSqlCharacters()
        {
            var sqlBuilder = new SelectSqlBuilder(MsSqlCharacters.Instance, "Column1");

            var sqlQuery = sqlBuilder
                .From("Table")
                .Where("Column2").IsEqualTo("FOO")
                .OrWhere("Column1").In(1, 2, 3)
                .ToSqlQuery();

            Assert.Equal("SELECT [Column1] FROM [Table] WHERE ([Column2] = @p0) OR ([Column1] IN (@p1,@p2,@p3))", sqlQuery.CommandText);

            Assert.Equal(4, sqlQuery.Arguments.Count);

            Assert.Equal(DbType.String, sqlQuery.Arguments[0].DbType);
            Assert.Equal("FOO", sqlQuery.Arguments[0].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[1].DbType);
            Assert.Equal(1, sqlQuery.Arguments[1].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[2].DbType);
            Assert.Equal(2, sqlQuery.Arguments[2].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[3].DbType);
            Assert.Equal(3, sqlQuery.Arguments[3].Value);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:26,代码来源:SelectSqlBuilderTests.cs

示例10: SelectWhereNotInArgsWithSqlCharacters

        public void SelectWhereNotInArgsWithSqlCharacters()
        {
            var sqlBuilder = new SelectSqlBuilder(MsSqlCharacters.Instance, "Column1");

            var sqlQuery = sqlBuilder
                .From("Table")
                .Where("Column1").NotIn(1, 2, 3)
                .ToSqlQuery();

            Assert.Equal("SELECT [Column1] FROM [Table] WHERE ([Column1] NOT IN (@p0,@p1,@p2))", sqlQuery.CommandText);

            Assert.Equal(3, sqlQuery.Arguments.Count);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[0].DbType);
            Assert.Equal(1, sqlQuery.Arguments[0].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[1].DbType);
            Assert.Equal(2, sqlQuery.Arguments[1].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[2].DbType);
            Assert.Equal(3, sqlQuery.Arguments[2].Value);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:22,代码来源:SelectSqlBuilderTests.cs

示例11: SelectWhereNotInMultipleSqlQueries

        public void SelectWhereNotInMultipleSqlQueries()
        {
            var subQuery1 = new SqlQuery("SELECT Id FROM Table WHERE Column = ?", 1024);
            var subQuery2 = new SqlQuery("SELECT Id FROM Table WHERE Column = ?", 2048);

            var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "Column1");

            var sqlQuery = sqlBuilder
                .From("Table")
                .Where("Column1").NotIn(subQuery1, subQuery2)
                .ToSqlQuery();

            Assert.Equal("SELECT Column1 FROM Table WHERE (Column1 NOT IN ((SELECT Id FROM Table WHERE Column = ?), (SELECT Id FROM Table WHERE Column = ?)))", sqlQuery.CommandText);

            Assert.Equal(2, sqlQuery.Arguments.Count);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[0].DbType);
            Assert.Equal(1024, sqlQuery.Arguments[0].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[1].DbType);
            Assert.Equal(2048, sqlQuery.Arguments[1].Value);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:22,代码来源:SelectSqlBuilderTests.cs

示例12: SelectWhereNotExistsSqlQuery

        public void SelectWhereNotExistsSqlQuery()
        {
            var subQuery = new SqlQuery("SELECT Id FROM Table WHERE Column = ?", 1024);

            var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "Column1");

            var sqlQuery = sqlBuilder
                .From("Table")
                .Where().NotExists(subQuery)
                .ToSqlQuery();

            Assert.Equal("SELECT Column1 FROM Table WHERE NOT EXISTS (SELECT Id FROM Table WHERE Column = ?)", sqlQuery.CommandText);

            Assert.Equal(1, sqlQuery.Arguments.Count);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[0].DbType);
            Assert.Equal(1024, sqlQuery.Arguments[0].Value);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:18,代码来源:SelectSqlBuilderTests.cs

示例13: SelectWhereNotBetweenWithSqlCharacters

        public void SelectWhereNotBetweenWithSqlCharacters()
        {
            var sqlBuilder = new SelectSqlBuilder(MsSqlCharacters.Instance, "Column1");

            var sqlQuery = sqlBuilder
                   .From("Table")
                   .Where("Column1").NotBetween(1, 10)
                   .ToSqlQuery();

            Assert.Equal("SELECT [Column1] FROM [Table] WHERE ([Column1] NOT BETWEEN @p0 AND @p1)", sqlQuery.CommandText);

            Assert.Equal(2, sqlQuery.Arguments.Count);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[0].DbType);
            Assert.Equal(1, sqlQuery.Arguments[0].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[1].DbType);
            Assert.Equal(10, sqlQuery.Arguments[1].Value);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:19,代码来源:SelectSqlBuilderTests.cs

示例14: SelectWhereNotBetween

        public void SelectWhereNotBetween()
        {
            var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "Column1");

            var sqlQuery = sqlBuilder
                   .From("Table")
                   .Where("Column1").NotBetween(1, 10)
                   .ToSqlQuery();

            Assert.Equal("SELECT Column1 FROM Table WHERE (Column1 NOT BETWEEN ? AND ?)", sqlQuery.CommandText);

            Assert.Equal(2, sqlQuery.Arguments.Count);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[0].DbType);
            Assert.Equal(1, sqlQuery.Arguments[0].Value);

            Assert.Equal(DbType.Int32, sqlQuery.Arguments[1].DbType);
            Assert.Equal(10, sqlQuery.Arguments[1].Value);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:19,代码来源:SelectSqlBuilderTests.cs

示例15: NotInThrowsArgumentNullExceptionForNullSqlQuery

        public void NotInThrowsArgumentNullExceptionForNullSqlQuery()
        {
            var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "CustomerId");

            Assert.Throws<ArgumentNullException>(
                () => sqlBuilder.From("Customer").Where("Column").NotIn((SqlQuery)null));
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:7,代码来源:SelectSqlBuilderTests.cs


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