public void 交易() { this.Inserts(); var memberToDb = new Member { ID = 1, NAME = "yao", AGE = 20, REMARK = TestHook.TestData }; using (var db = new MemberDb()) { db.BeginTransaction(); try { db.Insert(memberToDb); throw new Exception(); db.CommitTransaction(); } catch (Exception e) { db.RollbackTransaction(); } } }
private void Inserts() { var membersToDb = new List <Member>(); var identitiesToDb = new List <Identity>(); for (int i = 0; i < 10; i++) { membersToDb.Add(new Member { ID = i + 1, NAME = Name.FullName(), AGE = RandomNumber.Next(1, 120), REMARK = TestHook.TestData }); identitiesToDb.Add(new Identity { MEMBER_ID = membersToDb[i].ID, ACCOUNT = Name.First(), PASSWORD = "******", REMARK = TestHook.TestData }); } using (var db = new MemberDb()) { db.BeginTransaction(); try { //db.BulkCopy(membersToDb); for (int i = 0; i < membersToDb.Count; i++) { var member = membersToDb[i]; var identity = identitiesToDb[i]; db.Insert(member); db.Insert(identity); } db.CommitTransaction(); } catch (Exception e) { Console.WriteLine(db.LastQuery); db.RollbackTransaction(); } } }
public void 新增() { var memberToDb = new Member { ID = 1, NAME = "yao", AGE = 20, REMARK = TestHook.TestData }; using (var db = new MemberDb()) { var insertCount = db.Insert(memberToDb); Console.WriteLine(db.LastQuery); Assert.AreEqual(1, insertCount); } }
private Member Insert() { var memberToDb = new Member { ID = 12, NAME = "yao", AGE = 13, REMARK = TestHook.TestData }; using (var db = new MemberDb()) { db.Insert(memberToDb); } return(memberToDb); }