Example #1
0
        /// <summary>
        /// 同步模型结构到数据库
        /// </summary>
        /// <param name="modelType"></param>
        public static void SyncModelToDb(Type modelType)
        {
            var createSql = GetCreateSql(modelType);
            var dropSql   = $"DROP TABLE IF EXISTS `{GetTableName(modelType)}`;";
            var sql       = string.Concat(dropSql, Environment.NewLine, createSql);

            BaseDbService.Execute(sql);
        }
Example #2
0
        public static Tuple <List <string>, List <string> > GetClass()
        {
            var assembly = typeof(Account).Assembly;


            var toCreateModels = new List <string>();
            var existModels    = new List <string>();


            var existList = BaseDbService.Query <string>("show tables");

            foreach (var type in assembly.GetExportedTypes())
            {
                if (type.IsEnum)
                {
                    continue;
                }
                if (type.IsInterface)
                {
                    continue;
                }
                if (!type.FullName.Contains(packageName))
                {
                    continue;
                }

                var name = GetTableName(type);
                if (existList.Contains(name))
                {
                    existModels.Add(type.FullName);
                }
                else
                {
                    toCreateModels.Add(type.FullName);
                }
            }
            existModels.Sort();
            toCreateModels.Sort();

            return(Tuple.Create(existModels, toCreateModels));
        }