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


C# Database.Execute方法代码示例

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


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

示例1: ActualizarJornada

        public void ActualizarJornada(
            [Greedy]Jornada jornada)
        {
            var database = new Database(DatabaseHelper.Database);
            var sut = new PetaPocoJornadaCommands(database);

            sut.CrearJornada(jornada, DatabaseHelper.Usuario);

            var jornadaDbRow = database.FirstOrDefault<JornadaDbRow>(
                "Select * from Jornadas where IdJornada = @0", jornada.Id);

            jornadaDbRow.Should().NotBeNull();

            // Modificamos
            var nuevaPausa = new Pausa(jornada.Fin.Value, jornada.Fin.Value.AddHours(2));
            var idJornada = jornada.Id;
            jornada = new Jornada(
                jornada.Inicio,
                jornada.Fin.Value.AddDays(1),
                jornada.Pausas.Skip(1).Union(new[] { nuevaPausa }).ToArray());
            jornada.Id = idJornada;

            sut.ActualizarJornada(jornada, DatabaseHelper.Usuario);

            jornadaDbRow = database.FirstOrDefault<JornadaDbRow>(
                "Select * from Jornadas where IdJornada = @0", jornada.Id);

            jornadaDbRow.Should().NotBeNull();

            database.Execute("DELETE FROM Pausas WHERE IdJornada = @0", jornada.Id);
            database.Execute("DELETE FROM Jornadas WHERE IdJornada = @0", jornada.Id);
        }
开发者ID:hbiarge,项目名称:Testing-HackLab,代码行数:32,代码来源:PetaPocoJornadasCommandsTests.cs

示例2: DeleteClass

        public void DeleteClass(int classId)
        {
            using (var db = new Database(_connectionName))
            {
                var sql = Sql.Builder.Append("DELETE FROM dbo.Student WHERE ClassId = @0", classId);
                db.Execute(sql);

                sql = Sql.Builder.Append("DELETE FROM dbo.Class WHERE Id = @0", classId);
                db.Execute(sql);
            }
        }
开发者ID:vbhargav80,项目名称:QuantumTest,代码行数:11,代码来源:Repository.cs

示例3: ResetDatabase

        protected override void ResetDatabase()
        {
            using (var database = new Database("SQLiteTest"))
            {
                database.BeginTransaction();

                database.Execute(new Sql("DELETE FROM Entity"));
                database.Execute(new Sql("DELETE FROM sqlite_sequence WHERE name = @0", "Entity"));

                database.CompleteTransaction();
            }
        }
开发者ID:TrevorPilley,项目名称:MicroORM.Benchmark,代码行数:12,代码来源:NPoco.cs

示例4: Remove

 public void Remove(Database database)
 {
     string sql = "DELETE FROM transactions WHERE id=:id";
     Dictionary<string, object> parameters = new Dictionary<string, object>();
     parameters.Add(":id", id);
     database.Execute(sql, parameters);
 }
开发者ID:jsmnlcbls,项目名称:Loanbook,代码行数:7,代码来源:Transaction.cs

示例5: TearDown

 public void TearDown()
 {
     using (var db = new Database(DbConnection))
     {
         db.Execute(@"DROP TABLE Product");
     }
 }
开发者ID:v0id24,项目名称:ByndyuSoft.Infrastructure,代码行数:7,代码来源:InMemoryTestFixtureBase.cs

示例6: UpdateDatabase

        private static void UpdateDatabase(Database database)
        {
            database.CreateTable<Schedule>(false);
            database.CreateTable<Log>(false);

            database.Execute(@"
            IF NOT EXISTS(
            SELECT *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'uScheduler_Schedules'
            AND COLUMN_NAME = 'Headers')
            ALTER TABLE dbo.uScheduler_Schedules
            ADD [Headers] NTEXT"
            );

            database.Execute(@"
            IF NOT EXISTS(
            SELECT *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'uScheduler_Log'
            AND COLUMN_NAME = 'MachineName')
            ALTER TABLE dbo.uScheduler_Log
            ADD [MachineName] NVARCHAR(100)"
            );
        }
开发者ID:AffinityID,项目名称:uScheduler,代码行数:25,代码来源:SchedulerApplication.cs

示例7: TestExecuteWithInsert

 public void TestExecuteWithInsert()
 {
     dynamic database = new Database(new DbConnectionStub());
     database.Execute("insert into people values (?,?)", "Bob", 35);
     Assert.AreEqual("insert into people values (@p0,@p1)", DatabaseStub.Sql);
     Assert.AreEqual("Bob", DatabaseStub.Parameters[0]);
     Assert.AreEqual(35, DatabaseStub.Parameters[1]);
 }
开发者ID:jaimedp,项目名称:Simple.Data,代码行数:8,代码来源:DatabaseTest.cs

示例8: TestExecuteWithUpdate

 public void TestExecuteWithUpdate()
 {
     dynamic database = new Database(new DbConnectionStub());
     database.Execute("update people set name = ?, age = ? where id = ?", "Bob", 35, 1);
     Assert.AreEqual("update people set name = @p0, age = @p1 where id = @p2", DatabaseStub.Sql);
     Assert.AreEqual("Bob", DatabaseStub.Parameters[0]);
     Assert.AreEqual(35, DatabaseStub.Parameters[1]);
     Assert.AreEqual(1, DatabaseStub.Parameters[2]);
 }
开发者ID:jaimedp,项目名称:Simple.Data,代码行数:9,代码来源:DatabaseTest.cs

示例9: SqlServerTests

        public SqlServerTests()
        {
            _instance = TemporarySqlLocalDbInstance.Create(deleteFiles: true);

            _connection = _instance.CreateConnection();
            _connection.Open();

            _database = new Database(_connection);

            _database.Execute("create database [SqlServerTests]");
        }
开发者ID:StevenTCramer,项目名称:Respawn,代码行数:11,代码来源:SqlServerTests.cs

示例10: Save

 public void Save(Database database)
 {
     if (id == 0)
     {
         string sql = "INSERT INTO accounts (name, remarks) VALUES (:name, :remarks)";
         Dictionary<string, object> parameters = new Dictionary<string, object>();
         parameters.Add(":name", name);
         parameters.Add(":remarks", remarks);
         database.Execute(sql, parameters);
         id = database.LastInsertId();
     }
     else
     {
         string sql = "UPDATE accounts SET name=:name, remarks=:remarks WHERE id=:id";
         Dictionary<string, object> parameters = new Dictionary<string, object>();
         parameters.Add(":name", name);
         parameters.Add(":remarks", remarks);
         parameters.Add(":id", id);
         database.Execute(sql, parameters);
     }
 }
开发者ID:jsmnlcbls,项目名称:Loanbook,代码行数:21,代码来源:Account.cs

示例11: RestartTestDatabase

        public static void RestartTestDatabase()
        {
            var database = new Database("Presencia");

            using (var transaction = database.GetTransaction())
            {
                database.Execute("DELETE FROM Pausas;");
                database.Execute("DELETE FROM Jornadas;");
                database.Execute("DELETE FROM UsuariosRoles;");
                database.Execute("DELETE FROM Roles;");
                database.Execute("DELETE FROM Usuarios;");

                // Añadir usuarios y roles
                database.Execute("INSERT INTO Usuarios ([Usuario], [Password]) VALUES (@0, @1)", Usuario, "Prueba");
                database.Execute("INSERT INTO Roles ([Name]) VALUES (@0)", Rol);
                database.Execute("INSERT INTO UsuariosRoles ([Usuario], [Rol]) VALUES (@0, @1)", Usuario, Rol);

                // Añadir jornadas terminadas anteriores al día actual
                var dia = DateTime.Today.AddDays(-NumeroDiasCreados);

                for (var i = 0; i < NumeroDiasCreados; i++)
                {
                    var idJornada = database.ExecuteScalar<int>(
                        "INSERT INTO Jornadas ([Usuario],[Fecha],[Entrada],[Salida]) VALUES (@0, @1, @2, @3);\nSELECT SCOPE_IDENTITY() AS NewID;",
                        Usuario,
                        dia,
                        dia.AddHours(8),
                        dia.AddHours(16));

                    for (var j = 0; j < 4; j++)
                    {
                        var horaInicioPausa = 9 + j;
                        database.Execute(
                        "INSERT INTO Pausas ([IdJornada],[Inicio],[Fin]) VALUES (@0, @1, @2)",
                        idJornada,
                        dia.AddHours(horaInicioPausa),
                        dia.AddMinutes((horaInicioPausa * 60) + 30));
                    }

                    dia = dia.AddDays(1);
                }

                transaction.Complete();
            }
        }
开发者ID:hbiarge,项目名称:Testing-HackLab,代码行数:45,代码来源:DatabaseHelper.cs

示例12: Save

 public void Save(Database database)
 {
     if (id == 0)
     {
         string sql = "INSERT INTO transactions (account_id, date, amount, remarks) VALUES (:accountId, :date, :amount, :remarks)";
         Dictionary<string, object> parameters = new Dictionary<string, object>();
         parameters.Add(":accountId", account.Id);
         parameters.Add(":date", date);
         parameters.Add(":amount", amount);
         parameters.Add(":remarks", remarks);
         database.Execute(sql, parameters);
         id = database.LastInsertId();
     }
     else
     {
         string sql = "UPDATE transactions SET amount=:amount, date=:date, remarks=:remarks WHERE id=:id";
         Dictionary<string, object> parameters = new Dictionary<string, object>();
         parameters.Add(":amount", amount);
         parameters.Add(":date", date);
         parameters.Add(":remarks", remarks);
         parameters.Add(":id", id);
         database.Execute(sql, parameters);
     }
 }
开发者ID:jsmnlcbls,项目名称:Loanbook,代码行数:24,代码来源:Transaction.cs

示例13: Setup

        public void Setup()
        {
            using (var db = new Database(DbConnection))
            {
                db.Execute(@"CREATE TABLE Product (
                                    Product_Id INTEGER PRIMARY KEY AUTOINCREMENT,
                                    Name varchar(255) NOT NULL)");

                InsertProductWithName(db, FirstProductName);

                InsertProductWithName(db, SecondProductName);

                InsertProductWithName(db, ThirdProductName);
            }
        }
开发者ID:v0id24,项目名称:ByndyuSoft.Infrastructure,代码行数:15,代码来源:InMemoryTestFixtureBase.cs

示例14: Can_create_and_manipulate_sql_database

        public void Can_create_and_manipulate_sql_database()
        {
            using (var config = new LocalDb("test_database"))
            {
                var database = new Database(config.OpenConnection());

                database.Execute(
                @"CREATE TABLE Person
                (
                    Id int IDENTITY PRIMARY KEY,
                    Name varchar(60) NULL,
                );");

                database.Insert(new Person { Id = 1, Name = "Khalid Abuhakmeh" });
                var result = database.Query<Person>("select * from Person");
                Assert.True(result.Any());
            }
        }
开发者ID:cottsak,项目名称:DatabaseHelpersExample,代码行数:18,代码来源:Pudding.cs

示例15: CrearJornada

        public void CrearJornada(
            [Greedy]Jornada jornada)
        {
            var database = new Database(DatabaseHelper.Database);
            var sut = new PetaPocoJornadaCommands(database);

            sut.CrearJornada(jornada, DatabaseHelper.Usuario);

            var jornadaDbRow = database.FirstOrDefault<JornadaDbRow>(
                "Select * from Jornadas where IdJornada = @0", jornada.Id);

            jornadaDbRow.Should().NotBeNull();

            database.Execute("DELETE FROM Pausas WHERE IdJornada = @0", jornada.Id);
            database.Execute("DELETE FROM Jornadas WHERE IdJornada = @0", jornada.Id);
        }
开发者ID:hbiarge,项目名称:Testing-HackLab,代码行数:16,代码来源:PetaPocoJornadasCommandsTests.cs


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