v0.1.0 & FreeSql.Repository

This commit is contained in:
28810
2019-02-20 17:28:51 +08:00
parent 9222de0668
commit 204ab9f7d8
15 changed files with 78 additions and 53 deletions

View File

@ -72,6 +72,7 @@ namespace FreeSql.Internal {
if (attr._IsPrimary == null) attr._IsPrimary = trycol.IsPrimary;
if (attr._IsIdentity == null) attr._IsIdentity = trycol.IsIdentity;
if (attr._IsNullable == null) attr._IsNullable = trycol.IsNullable;
if (attr._IsIgnore == null) attr._IsIgnore = trycol.IsIgnore;
if (attr.DbDefautValue == null) attr.DbDefautValue = trycol.DbDefautValue;
return attr;
}

View File

@ -63,7 +63,9 @@ namespace FreeSql.Internal {
IsIdentity = false,
IsNullable = tp.Value.isnullable ?? true,
IsPrimary = false,
IsIgnore = false
};
if (colattr.IsIgnore) continue;
if (string.IsNullOrEmpty(colattr.DbType)) colattr.DbType = tp?.dbtypeFull ?? "varchar(255)";
colattr.DbType = colattr.DbType.ToUpper();
@ -101,7 +103,17 @@ namespace FreeSql.Internal {
}
trytb.Primarys = trytb.Columns.Values.Where(a => a.Attribute.IsPrimary == true).ToArray();
if (trytb.Primarys.Any() == false) {
trytb.Primarys = trytb.Columns.Values.Where(a => a.Attribute.IsIdentity == true).ToArray();
trytb.Primarys = trytb.Columns.Values.Where(a => string.Compare(a.Attribute.Name, "id", true) == 0).ToArray();
if (trytb.Primarys.Any() == false) {
trytb.Primarys = trytb.Columns.Values.Where(a => string.Compare(a.Attribute.Name, $"{trytb.DbName}id", true) == 0).ToArray();
if (trytb.Primarys.Any() == false) {
trytb.Primarys = trytb.Columns.Values.Where(a => string.Compare(a.Attribute.Name, $"{trytb.DbName}_id", true) == 0).ToArray();
if (trytb.Primarys.Any() == false) {
var identcols = trytb.Columns.Values.Where(a => a.Attribute.IsIdentity == true).FirstOrDefault();
if (identcols != null) trytb.Primarys = new[] { identcols };
}
}
}
foreach (var col in trytb.Primarys)
col.Attribute.IsPrimary = true;
}