本文整理汇总了C#中SQLiteConnection.RunInTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.RunInTransaction方法的具体用法?C# SQLiteConnection.RunInTransaction怎么用?C# SQLiteConnection.RunInTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLiteConnection
的用法示例。
在下文中一共展示了SQLiteConnection.RunInTransaction方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Insert
public void Insert(Student student)
{
var sqlPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "StudentDB.sqlite");
using (SQLiteConnection conn = new SQLiteConnection(new SQLitePlatformWinRT(), sqlPath))
{
conn.RunInTransaction(() =>
{
conn.Insert(student);
});
}
}
示例2: AddJob
public JobDto AddJob(Job job)
{
using (var databaseConnection = new SQLiteConnection(new SQLitePlatformWP8(), this.DatabaseFilePath))
{
databaseConnection.RunInTransaction(() =>
{
databaseConnection.Insert(job);
});
}
return Mapper.Map<JobDto>(job);
}
示例3: Delete
public void Delete(int Number)
{
var sqlPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "StudentDB.sqlite");
using (SQLiteConnection conn = new SQLiteConnection(new SQLitePlatformWinRT(), sqlPath))
{
var existingconact = conn.Query<Student>("select * from Students where Number =" + Number).FirstOrDefault();
if (existingconact != null)
{
conn.RunInTransaction(() =>
{
conn.Delete(existingconact);
});
}
}
}
示例4: Update
public void Update(Student student)
{
var sqlPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "StudentDB.sqlite");
using (SQLiteConnection conn = new SQLiteConnection(new SQLitePlatformWinRT(), sqlPath))
{
var existingStudent = conn.Query<Student>("select * from Students where Number =" + student.Number).FirstOrDefault();
if (existingStudent != null)
{
existingStudent.Name = student.Name;
existingStudent.Number = student.Number;
existingStudent.Department = student.Department;
conn.RunInTransaction(() =>
{
conn.Update(existingStudent);
});
}
}
}
示例5: DatabaseCleanUp
// Same method used to clean up the
// database.
private void DatabaseCleanUp (SQLiteConnection cnn)
{
// TODO: temporal method to clear old
// draft entries from DB. It should be removed
// in next versions.
cnn.Table <TimeEntryData> ().Delete (t => t.State == TimeEntryState.New);
// TODO: temporal method to clear
// data with wrong workspace defined.
var user = cnn.Table <UserData> ().FirstOrDefault ();
if (user != null && user.DefaultWorkspaceId != Guid.Empty) {
var tableNames = new List<string> { cnn.Table<TimeEntryData>().Table.TableName,
cnn.Table<ClientData>().Table.TableName,
cnn.Table<ProjectData>().Table.TableName,
cnn.Table<TagData>().Table.TableName,
cnn.Table<TaskData>().Table.TableName
};
cnn.RunInTransaction (() => {
foreach (var tableName in tableNames) {
var q = string.Concat ("UPDATE ", tableName ," SET WorkspaceId = '", user.DefaultWorkspaceId ,"' WHERE WorkspaceId = '", Guid.Empty, "'");
cnn.Execute (q);
}
});
}
}
示例6: DeleteItem
public string DeleteItem(int itemId)
{
string result = string.Empty;
using (var dbConn = new SQLiteConnection(App.SQLITE_PLATFORM, App.DB_PATH))
{
var existingItem = dbConn.Query<Media>("select * from Media where Id =" + itemId).FirstOrDefault();
if (existingItem != null)
{
dbConn.RunInTransaction(() =>
{
dbConn.Delete(existingItem);
if (dbConn.Delete(existingItem) > 0)
{
result = "Success";
}
else
{
result = "This item was not removed";
}
});
}
return result;
}
}