• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# CaptureSqlFilter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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
                    Or.EqualTo("select * from (\r select ssormlite1.*, rownum rnum from (\r select id, firstname, lastname, age  from person where (age = 42) order by person.id) ssormlite1\r where rownum <= 0 + 1) ssormlite2 where ssormlite2.rnum > 0").  //Oracle
                    Or.EqualTo("select * from (\r select ssormlite1.*, rownum rnum from (\r select id, firstname, lastname, age  from person where (age = @0) order by person.id) ssormlite1\r where rownum <= 0 + 1) ssormlite2 where ssormlite2.rnum > 0")   //Oracle with UseParameterizeSqlExpressions
                    );

                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:kouweizhong,项目名称:ServiceStack.OrmLite,代码行数:31,代码来源:CaptureSqlFilterTests.cs


示例17: Can_capture_Insert_Apis

        public void Can_capture_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.SqlStatements.Last().NormalizeSql(),
                    Does.Contain("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 }, p => new { p.FirstName, p.Age });

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

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


示例18: Can_capture_Delete_Apis

        public void Can_capture_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.SqlStatements.Last().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.Delete<Person>("Age = @age", new { age = 27 });
                i++; db.Delete(typeof(Person), "Age = @age", new { age = 27 });
                i++; db.Delete<Person>(p => p.Age == 27);
                i++; db.Delete(db.From<Person>().Where(p => p.Age == 27));

                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


示例19: Can_capture_basic_Query

        public void Can_capture_basic_Query()
        {
            using (var captured = new CaptureSqlFilter())
            using (var db = OpenDbConnection())
            {
                db.Where<Person>(new { Age = 27 });

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


示例20: Can_capture_command_all_Single_Apis

        public void Can_capture_command_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.SqlCommandHistory.Last().Sql.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)"). //SQLServer < 2012
                    Or.EqualTo("select id, firstname, lastname, age  from person where (age = 42) order by 1 offset 0 rows fetch next 1 rows only"). //SQLServer >= 2012
                    Or.EqualTo("select first 1 id, firstname, lastname, age  from person where (age = 42)")); //Firebird

            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.SqlCommandHistory.Count, Is.EqualTo(i));

                captured.SqlCommandHistory.PrintDump();

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CaptureType类代码示例发布时间:2022-05-24
下一篇:
C# CaptionCommand类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap