本文整理汇总了C#中DbManager.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# DbManager.BeginTransaction方法的具体用法?C# DbManager.BeginTransaction怎么用?C# DbManager.BeginTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbManager
的用法示例。
在下文中一共展示了DbManager.BeginTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DbTransactionTest
public void DbTransactionTest()
{
var dbManager = new DbManager(dbId);
dbManager.ExecuteNonQuery("create table if not exists a(c1 TEXT)", null);
var tx = dbManager.BeginTransaction();
dbManager.ExecuteNonQuery("insert into a(c1) values (?)", "s");
dbManager.ExecuteNonQuery("insert into a(c1) values (?)", "s2");
tx.Dispose();
dbManager.ExecuteNonQuery("insert into a(c1) values (?)", "s3");
}
示例2: SaveFeeds
public static void SaveFeeds(IEnumerable<FeedRow> feeds, string key, DateTime value)
{
using (var db = new DbManager(Constants.FeedDbId))
using (var tx = db.BeginTransaction())
{
db.ExecuteNonQuery(new SqlInsert("feed_last", true).InColumnValue("last_key", key).InColumnValue("last_date", value));
var now = DateTime.UtcNow;
foreach (var f in feeds)
{
if (0 >= f.Users.Count) continue;
var i = new SqlInsert("feed_aggregate", true)
.InColumnValue("id", f.Id)
.InColumnValue("tenant", f.Tenant)
.InColumnValue("product", f.ProductId)
.InColumnValue("module", f.ModuleId)
.InColumnValue("author", f.AuthorId)
.InColumnValue("group_id", f.GroupId)
.InColumnValue("created_date", f.CreatedDate)
.InColumnValue("json", f.Json)
.InColumnValue("keywords", f.Keywords)
.InColumnValue("aggregated_date", now);
db.ExecuteNonQuery(i);
if (f.ClearRightsBeforeInsert)
{
db.ExecuteNonQuery(
new SqlDelete("feed_users")
.Where("feed_id", f.Id)
);
}
foreach (var u in f.Users)
{
db.ExecuteNonQuery(
new SqlInsert("feed_users", true)
.InColumnValue("feed_id", f.Id)
.InColumnValue("user_id", u.ToString())
);
}
}
tx.Commit();
}
}
示例3: SetShare
public void SetShare(FileShareRecord r)
{
using (var dbManager = new DbManager(FileConstant.DatabaseId))
using (var tx = dbManager.BeginTransaction())
{
if (r.Share == FileShare.None)
{
if (r.EntryType == FileEntryType.Folder)
{
var entryIDs = dbManager.ExecuteList(Query("files_thirdparty_id_mapping")
.Select("hash_id")
.Where(Exp.Like("id", r.EntryId.ToString(), SqlLike.StartWith)))
.ConvertAll(x => x[0]);
dbManager.ExecuteNonQuery(Delete("files_security")
.Where(Exp.In("entry_id", entryIDs) &
Exp.Eq("subject", r.Subject.ToString())));
}
else
{
var d2 = Delete("files_security")
.Where(Exp.Eq("entry_id", MappingID(r.EntryId, true)))
.Where("entry_type", (int) FileEntryType.File)
.Where("subject", r.Subject.ToString());
dbManager.ExecuteNonQuery(d2);
}
}
else
{
var i = new SqlInsert("files_security", true)
.InColumnValue("tenant_id", r.Tenant)
.InColumnValue("entry_id", MappingID(r.EntryId, true))
.InColumnValue("entry_type", (int) r.EntryType)
.InColumnValue("subject", r.Subject.ToString())
.InColumnValue("owner", r.Owner.ToString())
.InColumnValue("security", (int) r.Share)
.InColumnValue("timestamp", DateTime.UtcNow);
dbManager.ExecuteNonQuery(i);
}
tx.Commit();
}
}
示例4: AddLink
public void AddLink(string obj, LoginProfile profile)
{
using (var db = new DbManager(dbid))
{
using (var tx = db.BeginTransaction())
{
db.ExecuteScalar<int>(
new SqlInsert(LinkTable, true)
.InColumnValue("id", obj)
.InColumnValue("uid", profile.HashId)
.InColumnValue("provider", profile.Provider)
.InColumnValue("profile", profile.ToSerializedString())
.InColumnValue("linked", DateTime.UtcNow)
);
tx.Commit();
}
}
}
示例5: Save
public static IEnumerable<string> Save(IEnumerable<string> ips, int tenant)
{
using (var db = new DbManager(dbId))
using (var tx = db.BeginTransaction())
{
var d = new SqlDelete(ipRestrictionsTable)
.Where("tenant", tenant);
db.ExecuteNonQuery(d);
var ipsList = ips.ToList();
foreach (var ip in ipsList)
{
var i = new SqlInsert(ipRestrictionsTable)
.InColumnValue("tenant", tenant)
.InColumnValue("ip", ip);
db.ExecuteNonQuery(i);
}
tx.Commit();
return ipsList;
}
}
示例6: Delete
public virtual void Delete(int projectId)
{
using (var db = new DbManager(DatabaseId))
{
using (var tx = db.BeginTransaction())
{
db.ExecuteNonQuery(new SqlDelete(ParticipantTable).Where("project_id", projectId));
db.ExecuteNonQuery(new SqlDelete(FollowingProjectTable).Where("project_id", projectId));
db.ExecuteNonQuery(new SqlDelete(ProjectTagTable).Where("project_id", projectId));
db.ExecuteNonQuery(Delete(TagsTable).Where(!Exp.In("id", new SqlQuery("projects_project_tag").Select("tag_id"))));
db.ExecuteNonQuery(Delete(TimeTrackingTable).Where("project_id", projectId));
var messages = db.ExecuteList(Query(MessagesTable)
.Select("concat('Message_', cast(id as char))")
.Where("project_id", projectId)).ConvertAll(r => (string) r[0]);
var milestones = db.ExecuteList(Query(MilestonesTable)
.Select("concat('Milestone_', cast(id as char))")
.Where("project_id", projectId)).ConvertAll(r => (string) r[0]);
var tasks = db.ExecuteList(Query(TasksTable)
.Select("concat('Task_', cast(id as char))")
.Where("project_id", projectId)).ConvertAll(r => (string) r[0]);
db.ExecuteNonQuery(Delete(CommentsTable).Where(Exp.In("target_uniq_id", messages)));
db.ExecuteNonQuery(Delete(CommentsTable).Where(Exp.In("target_uniq_id", milestones)));
db.ExecuteNonQuery(Delete(CommentsTable).Where(Exp.In("target_uniq_id", tasks)));
db.ExecuteNonQuery(Delete(MessagesTable).Where("project_id", projectId));
db.ExecuteNonQuery(Delete(MilestonesTable).Where("project_id", projectId));
db.ExecuteNonQuery(Delete(TasksTable).Where("project_id", projectId));
db.ExecuteNonQuery(Delete(ProjectsTable).Where("id", projectId));
tx.Commit();
AdminLog.PostAction("Projects: deleted project having ID={0}", projectId);
}
}
}
示例7: MailDbContext
public MailDbContext(string dbConnectionStringName, bool needTransaction = false)
{
DbManager = new DbManager(dbConnectionStringName);
if (needTransaction)
DbTransaction = DbManager.BeginTransaction(IsolationLevel.ReadUncommitted);
}
示例8: Delete
public virtual void Delete(int id)
{
using (var db = new DbManager(DatabaseId))
{
using (var tx = db.BeginTransaction())
{
db.ExecuteNonQuery(Delete(CommentsTable).Where("target_uniq_id", ProjectEntity.BuildUniqId<Task>(id)));
db.ExecuteNonQuery(Delete(TasksResponsibleTable).Where("task_id", id));
db.ExecuteNonQuery(Delete(TasksTable).Where("id", id));
tx.Commit();
}
}
}
示例9: RemoveAssociationFromToken
public void RemoveAssociationFromToken(string token)
{
using (var db = new DbManager(_dbId))
{
var transaction = db.BeginTransaction();
try
{
db.ExecuteNonQuery(new SqlUpdate(TOKEN_TABLE).Where("token", token).Set("associate_id", null));
transaction.Commit();
}
catch
{
transaction.Rollback();
}
}
}
示例10: Delete
public virtual void Delete(int projectId)
{
using (var db = new DbManager(DatabaseId))
{
using (var tx = db.BeginTransaction())
{
db.ExecuteNonQuery(new SqlDelete(ParticipantTable).Where("project_id", projectId));
db.ExecuteNonQuery(new SqlDelete(FollowingProjectTable).Where("project_id", projectId));
db.ExecuteNonQuery(new SqlDelete(ProjectTagTable).Where("project_id", projectId));
db.ExecuteNonQuery(Delete(TagsTable).Where(!Exp.In("id", new SqlQuery("projects_project_tag").Select("tag_id"))));
db.ExecuteNonQuery(Delete(TimeTrackingTable).Where("project_id", projectId));
var messages = db.ExecuteList(Query(MessagesTable)
.Select("concat('Message_', cast(id as char))")
.Where("project_id", projectId)).ConvertAll(r => (string) r[0]);
var milestones = db.ExecuteList(Query(MilestonesTable)
.Select("concat('Milestone_', cast(id as char))")
.Where("project_id", projectId)).ConvertAll(r => (string) r[0]);
var tasks = db.ExecuteList(Query(TasksTable)
.Select("id")
.Where("project_id", projectId)).ConvertAll(r => Convert.ToInt32(r[0]));
db.ExecuteNonQuery(Delete(CommentsTable).Where(Exp.In("target_uniq_id", messages)));
db.ExecuteNonQuery(Delete(CommentsTable).Where(Exp.In("target_uniq_id", milestones)));
db.ExecuteNonQuery(Delete(CommentsTable).Where(Exp.In("target_uniq_id", new object[]{ tasks.Select(r=> "Task_" + r) })));
db.ExecuteNonQuery(Delete(MessagesTable).Where("project_id", projectId));
db.ExecuteNonQuery(Delete(MilestonesTable).Where("project_id", projectId));
db.ExecuteNonQuery(Delete(TasksOrderTable).Where("project_id", projectId));
db.ExecuteNonQuery(Delete(TasksResponsibleTable).Where(Exp.In("task_id", tasks)));
db.ExecuteNonQuery(Delete(SubtasksTable).Where(Exp.In("task_id", tasks)));
db.ExecuteNonQuery(Delete(TasksTable).Where("project_id", projectId));
db.ExecuteNonQuery(Delete(ProjectsTable).Where("id", projectId));
tx.Commit();
}
}
}
示例11: SetProjectTags
public void SetProjectTags(int projectId, string[] tags)
{
using (var db = new DbManager(DatabaseId))
{
using (var tx = db.BeginTransaction(IsolationLevel.ReadUncommitted))
{
var tagsToDelete = db.ExecuteList(
new SqlQuery(ProjectTagTable).Select("tag_id").Where("project_id", projectId),
r => (int) r[0]);
db.ExecuteNonQuery(new SqlDelete(ProjectTagTable).Where("project_id", projectId));
foreach (var tag in tagsToDelete)
{
if (db.ExecuteScalar<int>(new SqlQuery(ProjectTagTable).Select("project_id").Where("tag_id", tag)) == 0)
{
db.ExecuteNonQuery(Delete(TagsTable).Where("id", tag));
}
}
foreach (var tag in tags)
{
var tagId = db.ExecuteScalar<int>(Query(TagsTable)
.Select("id")
.Where("lower(title)", tag.ToLower()));
if (tagId == 0)
{
tagId = db.ExecuteScalar<int>(
Insert(TagsTable)
.InColumnValue("id", 0)
.InColumnValue("title", tag)
.InColumnValue("last_modified_by", DateTime.UtcNow)
.Identity(1, 0, true));
}
db.ExecuteNonQuery(new SqlInsert(ProjectTagTable, true).InColumnValue("tag_id", tagId).InColumnValue("project_id", projectId));
}
tx.Commit();
}
}
}
示例12: DeleteFolder
public void DeleteFolder(object folderId)
{
var folder = ProviderInfo.GetFolderById(folderId);
using (var dbManager = new DbManager(FileConstant.DatabaseId))
{
using (var tx = dbManager.BeginTransaction())
{
var hashIDs = dbManager.ExecuteList(Query("files_thirdparty_id_mapping").Select("hash_id").Where(Exp.Like("id", folder.ServerRelativeUrl, SqlLike.StartWith))).ConvertAll(x => x[0]);
dbManager.ExecuteNonQuery(Delete("files_tag_link").Where(Exp.In("entry_id", hashIDs)));
dbManager.ExecuteNonQuery(Delete("files_tag").Where(Exp.EqColumns("0", Query("files_tag_link l").SelectCount().Where(Exp.EqColumns("tag_id", "id")))));
dbManager.ExecuteNonQuery(Delete("files_security").Where(Exp.In("entry_id", hashIDs)));
dbManager.ExecuteNonQuery(Delete("files_thirdparty_id_mapping").Where(Exp.In("hash_id", hashIDs)));
tx.Commit();
}
}
ProviderInfo.DeleteFolder((string)folderId);
}
示例13: UpdatePathInDB
protected void UpdatePathInDB(String oldValue, String newValue)
{
if (oldValue.Equals(newValue)) return;
using (var dbManager = new DbManager(FileConstant.DatabaseId))
{
using (var tx = dbManager.BeginTransaction())
{
var oldIDs = dbManager.ExecuteList(Query("files_thirdparty_id_mapping")
.Select("id")
.Where(Exp.Like("id", oldValue, SqlLike.StartWith)))
.ConvertAll(x => x[0].ToString());
foreach (var oldID in oldIDs)
{
var oldHashID = MappingID(oldID);
var newID = oldID.Replace(oldValue, newValue);
var newHashID = MappingID(newID);
dbManager.ExecuteNonQuery(Update("files_thirdparty_id_mapping")
.Set("id", newID)
.Set("hash_id", newHashID)
.Where(Exp.Eq("hash_id", oldHashID)));
dbManager.ExecuteNonQuery(Update("files_security")
.Set("entry_id", newHashID)
.Where(Exp.Eq("entry_id", oldHashID)));
dbManager.ExecuteNonQuery(Update("files_tag_link")
.Set("entry_id", newHashID)
.Where(Exp.Eq("entry_id", oldHashID)));
}
tx.Commit();
}
}
}
示例14: DeleteReccurence
public void DeleteReccurence(int taskId)
{
using (var db = new DbManager(DatabaseId))
{
using (var tx = db.BeginTransaction())
{
db.ExecuteNonQuery(Delete("projects_tasks_recurrence").Where("task_id", taskId));
tx.Commit();
}
}
}
示例15: Save
public virtual Subtask Save(Subtask subtask)
{
using (var db = new DbManager(DatabaseId))
{
using (var tr = db.BeginTransaction())
{
var insert = Insert(SubtasksTable)
.InColumnValue("id", subtask.ID)
.InColumnValue("task_id", subtask.Task)
.InColumnValue("title", subtask.Title)
.InColumnValue("responsible_id", subtask.Responsible.ToString())
.InColumnValue("status", subtask.Status)
.InColumnValue("create_by", subtask.CreateBy.ToString())
.InColumnValue("create_on", TenantUtil.DateTimeToUtc(subtask.CreateOn))
.InColumnValue("last_modified_by", subtask.LastModifiedBy.ToString())
.InColumnValue("last_modified_on", TenantUtil.DateTimeToUtc(subtask.LastModifiedOn))
.InColumnValue("status_changed", TenantUtil.DateTimeToUtc(subtask.StatusChangedOn, DateTime.Now))
.Identity(1, 0, true);
subtask.ID = db.ExecuteScalar<int>(insert);
tr.Commit();
return subtask;
}
}
}