- 补充 IDbFirst GetTableByDatabase 返回 uk/fk/index 名称,以便迁移;

This commit is contained in:
28810
2019-04-26 18:10:51 +08:00
parent 24df5d6107
commit 5bb90a974b
11 changed files with 145 additions and 110 deletions

View File

@ -77,7 +77,7 @@ namespace FreeSql.Internal {
IsIgnore = false,
MapType = p.PropertyType
};
if (colattr._IsNullable == null) colattr._IsNullable = tp.Value.isnullable;
if (colattr._IsNullable == null) colattr._IsNullable = tp?.isnullable;
if (string.IsNullOrEmpty(colattr.DbType)) colattr.DbType = tp?.dbtypeFull ?? "varchar(255)";
colattr.DbType = colattr.DbType.ToUpper();
@ -164,11 +164,21 @@ namespace FreeSql.Internal {
trycol.Attribute.IsPrimary = true;
}
}
foreach(var dbuk in dbtb.UniquesDict) {
foreach (var dbcol in dbuk.Value) {
if (trytb.Columns.TryGetValue(dbcol.Name, out var trycol) && trycol.Attribute.MapType == dbcol.CsType ||
trytb.ColumnsByCs.TryGetValue(dbcol.Name, out trycol) && trycol.Attribute.MapType == dbcol.CsType) {
trycol.Attribute.Unique = dbuk.Key;
}
}
}
}
}
} catch { }
trytb.Primarys = trytb.Columns.Values.Where(a => a.Attribute.IsPrimary == true).ToArray();
}
trytb.Uniques = trytb.Columns.Values.Where(a => !string.IsNullOrEmpty(a.Attribute.Unique))
.ToDictionary(a => a.Attribute.Unique, a => trytb.Columns.Values.Where(b => b.Attribute.Unique == a.Attribute.Unique).ToList());
tbc.AddOrUpdate(entity, trytb, (oldkey, oldval) => trytb);
#region virtual