Exemplo n.º 1
0
        static void TestTableName(DataAccessor dal, ITableMappable mapper)
        {
            var mapping = dal.GetTableName(typeof(Post));

            Console.WriteLine($"Original table name: {mapping.TableName}");

            dal.ChangeMappingTable(typeof(Post), mapper, DateTime.Parse("2019-09-05"));
            mapping = dal.GetTableName(typeof(Post));
            Console.WriteLine($"Update table name: {mapping.TableName}\n");
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据条件改变传入类型的映射数据表(此操作会导致当前操作的context释放掉,调用前需确保context的内容已保存)
        /// </summary>
        /// <typeparam name="T">条件类型</typeparam>
        /// <param name="type">要改变映射的实体类型</param>
        /// <param name="condition">改变条件</param>
        /// <exception cref="ArgumentException">type类型不支持</exception>
        /// <returns>改变后的数据表映射</returns>
        public TableAccessMapping ChangeMappingTable(Type type, ITableMappable mapper, object condition)
        {
            TableMappingRule rule = default;

            rule.MappingType = type;
            rule.Mapper      = mapper;
            rule.Condition   = condition;

            List <TableMappingRule> param = new List <TableMappingRule> {
                rule
            };
            var result = ChangeMappingTables(param);

            return(result[0]);
        }
Exemplo n.º 3
0
        static void TestChangeDb(DataAccessor dal, ITableMappable mapper)
        {
            Console.WriteLine("\nTest change Db");
            string dbPath = Directory.GetCurrentDirectory();

            dbPath = Path.Combine(dbPath, "Blogging_1.db");
            string conStr = $"Data Source={dbPath}";

            Console.WriteLine("Org Data:");
            var list = dal.GetAll <Blog>().ToList();

            PrintData(list);

            dal.ChangeDataBase(conStr);

            Console.WriteLine("Changed Data:");
            list = dal.GetAll <Blog>().ToList();
            PrintData(list);
        }
Exemplo n.º 4
0
        static void TestChangeTable(DataAccessor dal, ITableMappable mapper)
        {
            DateTime sept = DateTime.Parse("2019-09-05");
            DateTime oct  = DateTime.Parse("2019-10-05");

            dal.ChangeMappingTable(typeof(Post), mapper, oct);
            List <Post> octData = dal.GetAll <Post>().ToList();

            Console.WriteLine("Oct. data");
            foreach (Post item in octData)
            {
                Console.WriteLine(item);
            }

            dal.ChangeMappingTable(typeof(Post), mapper, sept);
            List <Post> septData = dal.GetAll <Post>().ToList();

            Console.WriteLine("Sept. data");
            foreach (Post item in septData)
            {
                Console.WriteLine(item);
            }
        }