コード例 #1
0
        static void BasicUsage(DataAccessor dal)
        {
            Console.WriteLine("\nTest BasicUsage");
            long newId = 2;

            // Add
            Console.WriteLine("Test Add");
            Console.WriteLine("Org data:");
            var list = dal.GetAll <Blog>().ToList();

            PrintData(list);
            Blog newData = new Blog {
                BlogId = newId, Rating = 666, Url = "https://blog.test.com"
            };

            dal.AddRecord(newData);
            dal.Save();
            Console.WriteLine("New data:");
            list = dal.GetAll <Blog>().ToList();
            PrintData(list);
            Console.WriteLine();

            // update
            Blog target = dal.GetByID <Blog>(newId);

            Console.WriteLine("Test Update");
            target.Url = "https://newurl.test.com";
            dal.Update(target);
            dal.Save();
            list = dal.GetAll <Blog>().ToList();
            PrintData(list);
            Console.WriteLine();

            // delete
            Console.WriteLine("Test Delete");
            dal.Delete(target);
            dal.Save();
            list = dal.GetAll <Blog>().ToList();
            PrintData(list);
            Console.WriteLine();
        }