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


C# CaptureSqlFilter类代码示例

本文整理汇总了C#中CaptureSqlFilter的典型用法代码示例。如果您正苦于以下问题:C# CaptureSqlFilter类的具体用法?C# CaptureSqlFilter怎么用?C# CaptureSqlFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Can_capture_command_Select_APIs

        public void Can_capture_command_Select_APIs()
        {
            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                int i = 0;
                i++; db.Select<Person>(x => x.Age > 40);

                var p = OrmLiteConfig.UseParameterizeSqlExpressions
                    ? "@0"  //Normalized
                    : "40";

                Assert.That(captured.SqlCommandHistory.Last().Sql.NormalizeSql(),
                    Is.EqualTo("select id, firstname, lastname, age  from person where (age > {0})".Fmt(p)));

                i++; db.Select<Person>(q => q.Where(x => x.Age > 40));
                i++; db.Select(db.From<Person>().Where(x => x.Age > 40));
                i++; db.Select<Person>("Age > 40");
                i++; db.Select<Person>("SELECT * FROM Person WHERE Age > 40");
                i++; db.Select<Person>("Age > @age", new { age = 40 });
                i++; db.Select<Person>("SELECT * FROM Person WHERE Age > @age", new { age = 40 });
                i++; db.Select<Person>("Age > @age", new Dictionary<string, object> { { "age", 40 } });
                i++; db.SelectFmt<Person>("Age > {0}", 40);
                i++; db.SelectFmt<Person>("SELECT * FROM Person WHERE Age > {0}", 40);
                i++; db.Where<Person>("Age", 27);
                i++; db.Where<Person>(new { Age = 27 });
                i++; db.SelectByIds<Person>(new[] { 1, 2, 3 });
                i++; db.SelectByIds<Person>(new[] { 1, 2, 3 });
                i++; db.SelectNonDefaults(new Person { Id = 1 });
                i++; db.SelectNonDefaults("Age > @Age", new Person { Age = 40 });
                i++; db.SelectLazy<Person>().ToList();
                i++; db.WhereLazy<Person>(new { Age = 27 }).ToList();
                i++; db.Select<Person>();
                i++; db.Single<Person>(x => x.Age == 42);
                i++; db.Single(db.From<Person>().Where(x => x.Age == 42));
                i++; db.Single<Person>(new { Age = 42 });
                i++; db.Single<Person>("Age = @age", new { age = 42 });
                i++; db.SingleById<Person>(1);
                i++; db.SingleWhere<Person>("Age", 42);
                i++; db.Exists<Person>(new { Age = 42 });
                i++; db.Exists<Person>("SELECT * FROM Person WHERE Age = @age", new { age = 42 });
                i++; db.ExistsFmt<Person>("Age = {0}", 42);
                i++; db.ExistsFmt<Person>("SELECT * FROM Person WHERE Age = {0}", 42);

                Assert.That(captured.SqlCommandHistory.Count, Is.EqualTo(i));

                captured.SqlCommandHistory.PrintDump();

            }
        }
开发者ID:brian6peng,项目名称:ServiceStack.OrmLite,代码行数:50,代码来源:CaptureSqlCommandFilterTests.cs

示例2: Can_capture_Select_APIs

        public void Can_capture_Select_APIs()
        {
            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                int i = 0;
                i++; db.Select<Person>(x => x.Age > 40);

                Assert.That(captured.SqlStatements.Last().NormalizeSql(),
                    Is.EqualTo("select id, firstname, lastname, age  from person where (age > 40)").
                    Or.EqualTo("select id, firstname, lastname, age  from person where (age > @0)"));

                i++; db.Select<Person>(q => q.Where(x => x.Age > 40));
                i++; db.Select(db.From<Person>().Where(x => x.Age > 40));
                i++; db.Select<Person>("Age > 40");
                i++; db.Select<Person>("SELECT * FROM Person WHERE Age > 40");
                i++; db.Select<Person>("Age > @age", new { age = 40 });
                i++; db.Select<Person>("SELECT * FROM Person WHERE Age > @age", new { age = 40 });
                i++; db.Select<Person>("Age > @age", new Dictionary<string, object> { { "age", 40 } });
                i++; db.SelectFmt<Person>("Age > {0}", 40);
                i++; db.SelectFmt<Person>("SELECT * FROM Person WHERE Age > {0}", 40);
                i++; db.Where<Person>("Age", 27);
                i++; db.Where<Person>(new { Age = 27 });
                i++; db.SelectByIds<Person>(new[] { 1, 2, 3 });
                i++; db.SelectByIds<Person>(new[] { 1, 2, 3 });
                i++; db.SelectNonDefaults(new Person { Id = 1 });
                i++; db.SelectNonDefaults("Age > @Age", new Person { Age = 40 });
                i++; db.SelectLazy<Person>().ToList();
                i++; db.WhereLazy<Person>(new { Age = 27 }).ToList();
                i++; db.Select<Person>();
                i++; db.Single<Person>(x => x.Age == 42);
                i++; db.Single(db.From<Person>().Where(x => x.Age == 42));
                i++; db.Single<Person>(new { Age = 42 });
                i++; db.Single<Person>("Age = @age", new { age = 42 });
                i++; db.SingleById<Person>(1);
                i++; db.SingleWhere<Person>("Age", 42);
                i++; db.Exists<Person>(new { Age = 42 });
                i++; db.Exists<Person>("SELECT * FROM Person WHERE Age = @age", new { age = 42 });
                i++; db.ExistsFmt<Person>("Age = {0}", 42);
                i++; db.ExistsFmt<Person>("SELECT * FROM Person WHERE Age = {0}", 42);

                Assert.That(captured.SqlStatements.Count, Is.EqualTo(i));

                var sql = string.Join(";\n", captured.SqlStatements.ToArray());
                sql.Print();
            }
        }
开发者ID:kouweizhong,项目名称:ServiceStack.OrmLite,代码行数:47,代码来源:CaptureSqlFilterTests.cs

示例3: Can_change_schema_at_runtime

        public void Can_change_schema_at_runtime()
        {
            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                var modelDef = SqlServerOrmLiteDialectProvider.GetModelDefinition(typeof(Poco));
                db.SingleById<Poco>(1);

                Assert.That(captured.SqlStatements.Last(), Is.StringContaining("Schema1"));

                modelDef.Schema = "Schema2";

                db.SingleById<Poco>(1);

                Assert.That(captured.SqlStatements.Last(), Is.StringContaining("Schema2"));
            }
        }
开发者ID:JackFong,项目名称:ServiceStack.OrmLite,代码行数:17,代码来源:MismatchSchemaTests.cs

示例4: Can_change_schema_at_runtime

        public void Can_change_schema_at_runtime()
        {
            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                var modelDef = OrmLiteUtils.GetModelDefinition(typeof(Poco));
                
                db.SingleById<Poco>(1);

                Assert.That(captured.SqlStatements.Last().ToLower(), Does.Contain("schema1"));

                modelDef.Schema = "schema2";

                db.SingleById<Poco>(1);

                Assert.That(captured.SqlStatements.Last().ToLower(), Does.Contain("schema2"));
            }
        }
开发者ID:ServiceStack,项目名称:ServiceStack.OrmLite,代码行数:18,代码来源:MismatchSchemaTests.cs

示例5: Can_capture_command_each_type_of_API

        public void Can_capture_command_each_type_of_API()
        {
            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                db.CreateTable<Person>();
                db.Select<Person>(x => x.Age > 40);
                db.Single<Person>(x => x.Age == 42);
                db.Count<Person>(x => x.Age < 50);
                db.Insert(new Person { Id = 7, FirstName = "Amy", LastName = "Winehouse" });
                db.Update(new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix" });
                db.Delete<Person>(new { FirstName = "Jimi", Age = 27 });
                db.SqlColumn<string>("SELECT LastName FROM Person WHERE Age < @age", 
                    new { age = 50 });
                db.SqlList<Person>("exec sp_name @firstName, @age", 
                    new { firstName = "aName", age = 1 });
                db.ExecuteNonQuery("UPDATE Person SET LastName={0} WHERE Id={1}"
                    .SqlFmt("WaterHouse", 7));

                captured.SqlCommandHistory.PrintDump();
            }
        }
开发者ID:navarromattal,项目名称:ServiceStack.OrmLite,代码行数:22,代码来源:CaptureSqlCommandFilterTests.cs

示例6: Can_capture_command_CreateTable_APIs

        public void Can_capture_command_CreateTable_APIs()
        {
            using (var db = OpenDbConnection())
            {
                db.DropTable<Person>();
            }

            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                int i = 0;
                i++; db.CreateTable<Person>();

                Assert.That(captured.SqlCommandHistory.Last().Sql.NormalizeSql(),
                            Is.StringStarting("create table person"));

                Assert.That(captured.SqlCommandHistory.Count, Is.EqualTo(i));

                captured.SqlCommandHistory.PrintDump();

            }
        }
开发者ID:navarromattal,项目名称:ServiceStack.OrmLite,代码行数:22,代码来源:CaptureSqlCommandFilterTests.cs

示例7: Can_capture_CreateTable_APIs

        public void Can_capture_CreateTable_APIs()
        {
            using (var db = OpenDbConnection())
            {
                db.DropTable<Person>();
            }

            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                int i = 0;
                i++; db.CreateTable<Person>();

                Assert.That(captured.SqlStatements.Last().NormalizeSql(),
                            Is.StringStarting("create table person"));

                Assert.That(captured.SqlStatements.Count, Is.EqualTo(i));

                var sql = string.Join(";\n", captured.SqlStatements.ToArray());
                sql.Print();
            }
        }
开发者ID:kouweizhong,项目名称:ServiceStack.OrmLite,代码行数:22,代码来源:CaptureSqlFilterTests.cs

示例8: Can_capture_CreateTable_APIs

        public void Can_capture_CreateTable_APIs()
        {
            using (var db = OpenDbConnection())
            {
                db.DropTable<Person>();
            }

            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                int i = 0;
                i++; db.CreateTable<Person>();

                Assert.That(captured.SqlStatements.Last().NormalizeSql(),
                            Does.Contain("create table person"));

                Assert.That(captured.SqlCommandHistory.Count, Is.EqualTo(i)
                    .Or.EqualTo(i + 1)); //Check table if exists

                var sql = string.Join(";\n", captured.SqlStatements.ToArray());
                sql.Print();
            }
        }
开发者ID:ServiceStack,项目名称:ServiceStack.OrmLite,代码行数:23,代码来源:CaptureSqlFilterTests.cs

示例9: Can_capture_command_Insert_Apis

        public void Can_capture_command_Insert_Apis()
        {
            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                int i = 0;
                i++; db.Insert(new Person { Id = 7, FirstName = "Amy", LastName = "Winehouse", Age = 27 });

                Assert.That(captured.SqlCommandHistory.Last().Sql.NormalizeSql(),
                    Is.StringStarting("insert into person (id,firstname,lastname,age) values"));

                i++; db.Insert(new Person { Id = 7, FirstName = "Amy", LastName = "Winehouse", Age = 27 });
                i++; db.InsertAll(new[] { new Person { Id = 10, FirstName = "Biggie", LastName = "Smalls", Age = 24 } });
                i++; db.InsertOnly(new PersonWithAutoId { FirstName = "Amy", Age = 27 }, ev => ev.Insert(p => new { p.FirstName, p.Age }));
                i++; db.InsertOnly(new PersonWithAutoId { FirstName = "Amy", Age = 27 }, ev => db.From<PersonWithAutoId>().Insert(p => new { p.FirstName, p.Age }));

                Assert.That(captured.SqlCommandHistory.Count, Is.EqualTo(i));

                captured.SqlCommandHistory.PrintDump();

            }
        }
开发者ID:navarromattal,项目名称:ServiceStack.OrmLite,代码行数:22,代码来源:CaptureSqlCommandFilterTests.cs

示例10: Can_capture_command_CustomSql_Apis

        public void Can_capture_command_CustomSql_Apis()
        {
            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                int i = 0;
                i++; db.SqlColumn<string>("SELECT LastName FROM Person WHERE Age < @age", new { age = 50 });

                Assert.That(captured.SqlCommandHistory.Last().Sql.NormalizeSql(),
                    Is.EqualTo("select lastname from person where age < @age"));

                i++; db.SqlColumn<string>("SELECT LastName FROM Person WHERE Age < @age", new { age = 50 });
                i++; db.SqlColumn<string>("SELECT LastName FROM Person WHERE Age < @age", new Dictionary<string, object> { { "age", 50 } });
                i++; db.SqlScalar<int>("SELECT COUNT(*) FROM Person WHERE Age < @age", new { age = 50 });
                i++; db.SqlScalar<int>("SELECT COUNT(*) FROM Person WHERE Age < @age", new Dictionary<string, object> { { "age", 50 } });

                i++; db.ExecuteNonQuery("UPDATE Person SET LastName={0} WHERE Id={1}".SqlFmt("WaterHouse", 7));
                i++; db.ExecuteNonQuery("UPDATE Person SET [email protected] WHERE [email protected]", new { name = "WaterHouse", id = 7 });

                i++; db.SqlList<Person>("exec sp_name @firstName, @age", new { firstName = "aName", age = 1 });
                i++; db.SqlScalar<Person>("exec sp_name @firstName, @age", new { firstName = "aName", age = 1 });

                Assert.That(captured.SqlCommandHistory.Count, Is.EqualTo(i));

                captured.SqlCommandHistory.PrintDump();

            }
        }
开发者ID:navarromattal,项目名称:ServiceStack.OrmLite,代码行数:28,代码来源:CaptureSqlCommandFilterTests.cs

示例11: Can_capture_command_Delete_Apis

        public void Can_capture_command_Delete_Apis()
        {
            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                int i = 0;
                i++; db.Delete<Person>(new { FirstName = "Jimi", Age = 27 });

                Assert.That(captured.SqlCommandHistory.Last().Sql.NormalizeSql(),
                    Is.EqualTo("delete from person where [email protected] and [email protected]"));

                i++; db.Delete<Person>(new { FirstName = "Jimi", Age = 27 });
                i++; db.Delete(new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27 });
                i++; db.DeleteNonDefaults(new Person { FirstName = "Jimi", Age = 27 });
                i++; db.DeleteById<Person>(1);
                i++; db.DeleteByIds<Person>(new[] { 1, 2, 3 });
                i++; db.DeleteFmt<Person>("Age = {0}", 27);
                i++; db.DeleteFmt(typeof(Person), "Age = {0}", 27);
                i++; db.Delete<Person>(p => p.Age == 27);
                i++; db.Delete<Person>(ev => ev.Where(p => p.Age == 27));
                i++; db.Delete(db.From<Person>().Where(p => p.Age == 27));
                i++; db.DeleteFmt<Person>(where: "Age = {0}".SqlFmt(27));
                i++; db.DeleteFmt(table: "Person", where: "Age = {0}".SqlFmt(27));

                Assert.That(captured.SqlCommandHistory.Count, Is.EqualTo(i));

                captured.SqlCommandHistory.PrintDump();

            }
        }
开发者ID:navarromattal,项目名称:ServiceStack.OrmLite,代码行数:30,代码来源:CaptureSqlCommandFilterTests.cs

示例12: Can_capture_command_Update_Apis

        public void Can_capture_command_Update_Apis()
        {
            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                int i = 0;
                i++; db.Update(new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27 });

                Assert.That(captured.SqlCommandHistory.Last().Sql.NormalizeSql(),
                    Is.StringStarting("update person set [email protected], [email protected]"));

                i++; db.Update(new[] { new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27 } });
                i++; db.UpdateAll(new[] { new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27 } });
                i++; db.Update(new Person { Id = 1, FirstName = "JJ", Age = 27 }, p => p.LastName == "Hendrix");
                i++; db.Update<Person>(new { FirstName = "JJ" }, p => p.LastName == "Hendrix");
                i++; db.UpdateNonDefaults(new Person { FirstName = "JJ" }, p => p.LastName == "Hendrix");
                i++; db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName);
                i++; db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName, p => p.LastName == "Hendrix");
                i++; db.UpdateOnly(new Person { FirstName = "JJ", LastName = "Hendo" }, ev => ev.Update(p => p.FirstName));
                i++; db.UpdateOnly(new Person { FirstName = "JJ" }, ev => ev.Update(p => p.FirstName).Where(x => x.FirstName == "Jimi"));
                i++; db.UpdateFmt<Person>(set: "FirstName = {0}".SqlFmt("JJ"), where: "LastName = {0}".SqlFmt("Hendrix"));
                i++; db.UpdateFmt(table: "Person", set: "FirstName = {0}".SqlFmt("JJ"), where: "LastName = {0}".SqlFmt("Hendrix"));

                Assert.That(captured.SqlCommandHistory.Count, Is.EqualTo(i));

                captured.SqlCommandHistory.PrintDump();

            }
        }
开发者ID:navarromattal,项目名称:ServiceStack.OrmLite,代码行数:29,代码来源:CaptureSqlCommandFilterTests.cs

示例13: Can_capture_command_all_Scalar_Apis

        public void Can_capture_command_all_Scalar_Apis()
        {
            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                int i = 0;
                i++; db.Scalar<Person, int>(x => Sql.Max(x.Age));

                Assert.That(captured.SqlCommandHistory.Last().Sql.NormalizeSql(),
                    Is.EqualTo("select max(age)  from person"));

                i++; db.Scalar<Person, int>(x => Sql.Max(x.Age));
                i++; db.Scalar<Person, int>(x => Sql.Max(x.Age), x => x.Age < 50);
                i++; db.Count<Person>(x => x.Age < 50);
                i++; db.Count(db.From<Person>().Where(x => x.Age < 50));
                i++; db.Scalar<int>("SELECT COUNT(*) FROM Person WHERE Age > @age", new { age = 40 });
                i++; db.ScalarFmt<int>("SELECT COUNT(*) FROM Person WHERE Age > {0}", 40);

                i++; db.SqlScalar<int>("SELECT COUNT(*) FROM Person WHERE Age < @age", new { age = 50 });
                i++; db.SqlScalar<int>("SELECT COUNT(*) FROM Person WHERE Age < @age", new Dictionary<string, object> { { "age", 50 } });

                Assert.That(captured.SqlCommandHistory.Count, Is.EqualTo(i));

                captured.SqlCommandHistory.PrintDump();

            }
        }
开发者ID:navarromattal,项目名称:ServiceStack.OrmLite,代码行数:27,代码来源:CaptureSqlCommandFilterTests.cs

示例14: Can_capture_Update_Apis

        public void Can_capture_Update_Apis()
        {
            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                int i = 0;
                i++; db.Update(new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27 });

                Assert.That(captured.SqlStatements.Last().NormalizeSql(),
                    Does.StartWith("update person set [email protected], [email protected]"));

                i++; db.Update(new[] { new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27 } });
                i++; db.UpdateAll(new[] { new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27 } });
                i++; db.Update(new Person { Id = 1, FirstName = "JJ", Age = 27 }, p => p.LastName == "Hendrix");
                i++; db.Update<Person>(new { FirstName = "JJ" }, p => p.LastName == "Hendrix");
                i++; db.UpdateNonDefaults(new Person { FirstName = "JJ" }, p => p.LastName == "Hendrix");
                i++; db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName);
                i++; db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName, p => p.LastName == "Hendrix");
                i++; db.UpdateOnly(new Person { FirstName = "JJ", LastName = "Hendo" }, db.From<Person>().Update(p => p.FirstName));
                i++; db.UpdateOnly(new Person { FirstName = "JJ" }, db.From<Person>().Update(p => p.FirstName).Where(x => x.FirstName == "Jimi"));

                Assert.That(captured.SqlStatements.Count, Is.EqualTo(i));

                var sql = string.Join(";\n", captured.SqlStatements.ToArray());
                sql.Print();
            }
        }
开发者ID:ServiceStack,项目名称:ServiceStack.OrmLite,代码行数:27,代码来源:CaptureSqlFilterTests.cs

示例15: Can_capture_all_Single_Apis

        public void Can_capture_all_Single_Apis()
        {
            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                int i = 0;
                i++; db.Single<Person>(x => x.Age == 42);

                Assert.That(captured.SqlStatements.Last().NormalizeSql(),
                    Is.EqualTo("select id, firstname, lastname, age  from person where (age = 42) limit 1").
                    Or.EqualTo("select top 1 id, firstname, lastname, age  from person where (age = 42)").
                    Or.EqualTo("select id, firstname, lastname, age  from person where (age = 42) order by 1 offset 0 rows fetch next 1 rows only")); //VistaDB

                i++; db.ExistsFmt<Person>("Age = {0}", 42);
                i++; db.Single(db.From<Person>().Where(x => x.Age == 42));
                i++; db.Single<Person>(new { Age = 42 });
                i++; db.Single<Person>("Age = @age", new { age = 42 });
                i++; db.SingleFmt<Person>("Age = {0}", 42);
                i++; db.SingleById<Person>(1);
                i++; db.ExistsFmt<Person>("Age = {0}", 42);
                i++; db.SingleWhere<Person>("Age", 42);

                Assert.That(captured.SqlStatements.Count, Is.EqualTo(i));

                var sql = string.Join(";\n", captured.SqlStatements.ToArray());
                sql.Print();
            }
        }
开发者ID:JackFong,项目名称:ServiceStack.OrmLite,代码行数:28,代码来源:CaptureSqlFilterTests.cs


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