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

@ -16,7 +16,7 @@ namespace FreeSql.DataAnnotations {
/// </summary>
public string DbType { get; set; }
internal bool? _IsPrimary, _IsIdentity, _IsNullable;
internal bool? _IsPrimary, _IsIdentity, _IsNullable, _IsIgnore;
/// <summary>
/// 主键
/// </summary>
@ -29,6 +29,10 @@ namespace FreeSql.DataAnnotations {
/// 是否可DBNull
/// </summary>
public bool IsNullable { get => _IsNullable ?? false; set => _IsNullable = value; }
/// <summary>
/// 忽略此列,不迁移、不插入
/// </summary>
public bool IsIgnore { get => _IsIgnore ?? false; set => _IsIgnore = value; }
/// <summary>
/// 数据库默认值

View File

@ -50,5 +50,12 @@ namespace FreeSql.DataAnnotations {
_column.IsNullable = value;
return this;
}
/// <summary>
/// 忽略此列,不迁移、不插入
/// </summary>
public ColumnFluent IsIgnore(bool value) {
_column.IsIgnore = value;
return this;
}
}
}

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.0.14</Version>
<Version>0.1.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors>
<Description>打造 .NETCore 最方便的 ORMDbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>

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;
}