Beispiel #1
0
        private static void UpdateComment(MyAbpDbContext context, Type tableType)
        {
            string tableName;

            UpdateTableComment(context, tableType, out tableName);
            UpdateColumnComment(context, tableType, tableName);
        }
Beispiel #2
0
        public static void UpdateColumnComment(MyAbpDbContext context, Type tableType, string tableName)
        {
            foreach (var prop in tableType.GetProperties())
            {
                var propDateType = string.Empty;

                if (prop.PropertyType.IsClass && prop.PropertyType != typeof(string))
                {
                    continue;
                }
                var attrs         = prop.GetCustomAttributes(typeof(CommentAttribute), false);
                var columnComment = attrs.Length > 0 ? ((CommentAttribute)attrs[0]).Comments : string.Empty;

                if (prop.PropertyType == typeof(string))
                {
                    var lengthAttrs = prop.GetCustomAttributes(typeof(MaxLengthAttribute), false);
                    if (lengthAttrs.Length == 0)
                    {
                        continue;
                    }
                    var length = ((MaxLengthAttribute)lengthAttrs[0]).Length;
                    propDateType = $"varchar({length})";
                }

                if (prop.PropertyType == typeof(DateTime?) || prop.PropertyType == typeof(DateTime))
                {
                    propDateType = "Datetime";
                }
                if (prop.PropertyType == typeof(long) || prop.PropertyType == typeof(long?))
                {
                    propDateType = "BIGINT(20)";
                }

                if (prop.PropertyType == typeof(bool) || prop.PropertyType == typeof(bool?))
                {
                    propDateType = "TINYINT(1)";
                }

                if (prop.PropertyType == typeof(decimal) || prop.PropertyType == typeof(decimal?))
                {
                    propDateType = "decimal(18, 2)";
                }

                if (prop.PropertyType.IsEnum || prop.PropertyType == typeof(int) || prop.PropertyType == typeof(int?))
                {
                    var valueAttrs   = prop.GetCustomAttributes(typeof(DefaultValueAttribute), false);
                    var defaultValue = valueAttrs.Length > 0 ? ((DefaultValueAttribute)valueAttrs[0]).Value.ToString() : string.Empty;
                    propDateType = string.IsNullOrEmpty(defaultValue) ? "int" : $"int default {defaultValue}";
                }

                if (prop.PropertyType == typeof(byte[]))
                {
                    propDateType = "longblob";
                }

                context.Database.UpdateColumnComment(tableName, prop.Name, propDateType.ToUpper(), columnComment);
            }
        }
Beispiel #3
0
        public static void SeedHostDb(MyAbpDbContext context)
        {
            context.SuppressAutoSetTenantId = true;

            // Host seed
            new InitialHostDbBuilder(context).Create();

            // Default tenant seed (in host database).
            new DefaultTenantBuilder(context).Create();
            new TenantRoleAndUserBuilder(context, 1).Create();
        }
Beispiel #4
0
        public void UpdateComment(MyAbpDbContext context)
        {
            var properties = typeof(MyAbpDbContext).GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

            foreach (var prop in properties)
            {
                if (prop.PropertyType.Name.Contains("IDbSet"))
                {
                    var tableType = prop.PropertyType.GetGenericArguments()[0];
                    UpdateComment(context, tableType);
                }
            }
        }
Beispiel #5
0
 public DefaultTenantBuilder(MyAbpDbContext context)
 {
     _context = context;
 }
Beispiel #6
0
 public DefaultEditionCreator(MyAbpDbContext context)
 {
     _context = context;
 }
Beispiel #7
0
 public static void UpdateTableComment(MyAbpDbContext context, Type tableType, out string tableName)
 {
     tableName = context.GetTableName(tableType);
 }
 public DefaultSettingsCreator(MyAbpDbContext context)
 {
     _context = context;
 }
Beispiel #9
0
 public HostRoleAndUserCreator(MyAbpDbContext context)
 {
     _context = context;
 }
Beispiel #10
0
 public DefaultTenantCreator(MyAbpDbContext context)
 {
     _context = context;
 }
Beispiel #11
0
 public InitialHostDbBuilder(MyAbpDbContext context)
 {
     _context = context;
 }
Beispiel #12
0
 public TenantRoleAndUserBuilder(MyAbpDbContext context, int tenantId)
 {
     _context  = context;
     _tenantId = tenantId;
 }
Beispiel #13
0
 public DefaultLanguagesCreator(MyAbpDbContext context)
 {
     _context = context;
 }
Beispiel #14
0
 public DemoDataCreator(MyAbpDbContext context)
 {
     _context = context;
 }