| | |
| | | } |
| | | #endregion |
| | | } |
| | | else |
| | | { |
| | | List<string> columnNames = dbContext.Db.DbMaintenance.GetColumnInfosByTableName(t.Name, false).Select(x => x.DbColumnName).ToList(); |
| | | if (t.GetProperties().FirstOrDefault(x => !columnNames.Contains(x.Name)) != null) |
| | | { |
| | | bool isChange = true; |
| | | List<PropertyInfo> propertyInfos = t.GetProperties().Where(x => !columnNames.Contains(x.Name)).ToList(); |
| | | for (int i = 0; i < propertyInfos.Count; i++) |
| | | { |
| | | PropertyInfo propertyInfo = propertyInfos[i]; |
| | | SugarColumn? sugarColumn = propertyInfo.GetCustomAttribute<SugarColumn>(); |
| | | if (sugarColumn != null) |
| | | { |
| | | if (!sugarColumn.IsIgnore) |
| | | { |
| | | if (!sugarColumn.IsNullable) |
| | | { |
| | | isChange = false; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (isChange) |
| | | dbContext.Db.CodeFirst.InitTables(t); |
| | | } |
| | | } |
| | | //else |
| | | //{ |
| | | // List<string> columnNames = dbContext.Db.DbMaintenance.GetColumnInfosByTableName(t.Name, false).Select(x => x.DbColumnName).ToList(); |
| | | // if (t.GetProperties().FirstOrDefault(x => !columnNames.Contains(x.Name)) != null) |
| | | // { |
| | | // bool isChange = true; |
| | | // List<PropertyInfo> propertyInfos = t.GetProperties().Where(x => !columnNames.Contains(x.Name)).ToList(); |
| | | // for (int i = 0; i < propertyInfos.Count; i++) |
| | | // { |
| | | // PropertyInfo propertyInfo = propertyInfos[i]; |
| | | // SugarColumn? sugarColumn = propertyInfo.GetCustomAttribute<SugarColumn>(); |
| | | // if (sugarColumn != null) |
| | | // { |
| | | // if (!sugarColumn.IsIgnore) |
| | | // { |
| | | // if (!sugarColumn.IsNullable) |
| | | // { |
| | | // isChange = false; |
| | | // break; |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // if (isChange) |
| | | // dbContext.Db.CodeFirst.InitTables(t); |
| | | // } |
| | | //} |
| | | }); |
| | | ConsoleHelper.WriteSuccessLine($"Tables Created Successfully!"); |
| | | Console.WriteLine(); |