本文整理汇总了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);
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例5: TearDown
public void TearDown()
{
using (var db = new Database(DbConnection))
{
db.Execute(@"DROP TABLE Product");
}
}
示例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)"
);
}
示例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]);
}
示例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]);
}
示例9: SqlServerTests
public SqlServerTests()
{
_instance = TemporarySqlLocalDbInstance.Create(deleteFiles: true);
_connection = _instance.CreateConnection();
_connection.Open();
_database = new Database(_connection);
_database.Execute("create database [SqlServerTests]");
}
示例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);
}
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
}
示例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);
}