本文整理匯總了C#中Tracker.SqlServer.CodeFirst.TrackerContext.BeginTransaction方法的典型用法代碼示例。如果您正苦於以下問題:C# TrackerContext.BeginTransaction方法的具體用法?C# TrackerContext.BeginTransaction怎麽用?C# TrackerContext.BeginTransaction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Tracker.SqlServer.CodeFirst.TrackerContext
的用法示例。
在下文中一共展示了TrackerContext.BeginTransaction方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: MaintainAcrossSaves
public void MaintainAcrossSaves()
{
var auditConfiguration = AuditConfiguration.Default;
auditConfiguration.IncludeRelationships = true;
auditConfiguration.LoadRelationships = true;
auditConfiguration.DefaultAuditable = true;
auditConfiguration.MaintainAcrossSaves = true;
// customize the audit for Task entity
//auditConfiguration.IsAuditable<Task>()
// .NotAudited(t => t.TaskExtended)
// .FormatWith(t => t.Status, v => FormatStatus(v));
// set name as the display member when status is a foreign key
auditConfiguration.IsAuditable<Status>()
.DisplayMember(t => t.Name);
var db = new TrackerContext();
var tran = db.BeginTransaction();
var audit = db.BeginAudit();
var user = db.Users.Find(1);
user.Comment = "Testing: " + DateTime.Now.Ticks;
var task = new Task()
{
AssignedId = 1,
StatusId = 1,
PriorityId = 2,
Summary = "Summary: " + DateTime.Now.Ticks,
CreatedId = 1,
CreatedDate = DateTime.Now,
ModifiedDate = DateTime.Now
};
db.Tasks.Add(task);
db.SaveChanges();
Assert.IsNotNull(audit.LastLog);
Assert.AreEqual(2, audit.LastLog.Entities.Count);
var task2 = db.Tasks.Find(1);
task2.PriorityId = 2;
task2.StatusId = 2;
task2.Summary = "Summary: " + DateTime.Now.Ticks;
db.SaveChanges();
Assert.IsNotNull(audit.LastLog);
Assert.AreEqual(3, audit.LastLog.Entities.Count);
var log = audit.LastLog;
Assert.IsNotNull(log);
string xml = log.ToXml();
Assert.IsNotNull(xml);
foreach (var property in log.Entities.SelectMany(e => e.Properties))
{
Assert.AreNotEqual(property.Current, "{error}");
Assert.AreNotEqual(property.Original, "{error}");
}
//undo work
tran.Rollback();
}