コード例 #1
0
ファイル: Program.cs プロジェクト: ffhighwind/DapperExtraCRUD
        public static void Main()
        {
            DB.Employees.GetList();             // caches all employees in the database

            try {
                using (DbCacheTransaction transaction = DB.Employees.BeginTransaction()) {
                    Employee emp = new Employee()
                    {
                        DateOfBirth = new DateTime(2000, 2, 15),
                        FirstName   = "Jack",
                        LastName    = "Black",
                        HireDate    = DB.GetDate(),
                        UserName    = "******",
                        ManagerID   = 2,
                    };
                    EmployeeItem empItem = DB.Employees.Insert(emp);                     // automatically uses the transaction
                    Console.WriteLine("Manager: " + empItem.Manager.Name + "\nAge: " + empItem.Manager.Age);
                    transaction.Commit();
                }
            }
            catch (Exception ex) {
                // roll back cache to before the transaction
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            // etc...
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ffhighwind/DapperExtraCRUD
        public bool Load()
        {
            EmployeeItem value = DB.Employees.Get(CacheValue);

            return(value == this);
        }