private static void UpdateComment(MyAbpDbContext context, Type tableType) { string tableName; UpdateTableComment(context, tableType, out tableName); UpdateColumnComment(context, tableType, tableName); }
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); } }
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(); }
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); } } }
public DefaultTenantBuilder(MyAbpDbContext context) { _context = context; }
public DefaultEditionCreator(MyAbpDbContext context) { _context = context; }
public static void UpdateTableComment(MyAbpDbContext context, Type tableType, out string tableName) { tableName = context.GetTableName(tableType); }
public DefaultSettingsCreator(MyAbpDbContext context) { _context = context; }
public HostRoleAndUserCreator(MyAbpDbContext context) { _context = context; }
public DefaultTenantCreator(MyAbpDbContext context) { _context = context; }
public InitialHostDbBuilder(MyAbpDbContext context) { _context = context; }
public TenantRoleAndUserBuilder(MyAbpDbContext context, int tenantId) { _context = context; _tenantId = tenantId; }
public DefaultLanguagesCreator(MyAbpDbContext context) { _context = context; }
public DemoDataCreator(MyAbpDbContext context) { _context = context; }