コード例 #1
0
        /// <summary>
        /// 获取创建表的SQL语句
        /// </summary>
        public static string GetCreateTableSQL <T>(this DbConnection connection) where T : BaseEntity
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(DbTableHelper.CreateTableSQL <T>());
            sb.AppendLine(DbTableHelper.CreateIndexSQL <T>());
            return(sb.ToString());
        }
コード例 #2
0
        /// <summary>
        /// 创建数据表
        /// </summary>
        public static async Task CreateTableAsync <T>(this DbConnection connection) where T : BaseEntity
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            await connection.ExecuteNonQueryAsync(DbTableHelper.CreateTableSQL <T>());

            string createIndexSql = DbTableHelper.CreateIndexSQL <T>();

            if (!string.IsNullOrWhiteSpace(createIndexSql))
            {
                await connection.ExecuteNonQueryAsync(createIndexSql);
            }
        }