mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 补充 nuget 包增加 xmlDoc 编译;
- 调整 Column.Unique 定义规则,解决同一属性不可配置多次的问题;
This commit is contained in:
parent
d49be984bd
commit
163fe89bd4
@ -45,11 +45,11 @@ namespace FreeSql.Tests.MySql {
|
||||
[Column(Unique = "uk_phone")]
|
||||
public string phone { get; set; }
|
||||
|
||||
[Column(Unique = "uk_group_index")]
|
||||
[Column(Unique = "uk_group_index, uk_group_index22")]
|
||||
public string group { get; set; }
|
||||
[Column(Unique = "uk_group_index11")]
|
||||
[Column(Unique = "uk_group_index")]
|
||||
public int index { get; set; }
|
||||
[Column(Unique = "uk_group_index222")]
|
||||
[Column(Unique = "uk_group_index22")]
|
||||
public string index22 { get; set; }
|
||||
}
|
||||
|
||||
|
@ -45,11 +45,11 @@ namespace FreeSql.Tests.Oracle {
|
||||
[Column(Unique = "uk_phone")]
|
||||
public string phone { get; set; }
|
||||
|
||||
[Column(Unique = "uk_group_index")]
|
||||
[Column(Unique = "uk_group_index, uk_group_index22")]
|
||||
public string group { get; set; }
|
||||
[Column(Unique = "uk_group_index11")]
|
||||
[Column(Unique = "uk_group_index")]
|
||||
public int index { get; set; }
|
||||
[Column(Unique = "uk_group_index222")]
|
||||
[Column(Unique = "uk_group_index22")]
|
||||
public string index22 { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
|
@ -52,11 +52,11 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
[Column(Unique = "uk_phone")]
|
||||
public string phone { get; set; }
|
||||
|
||||
[Column(Unique = "uk_group_index")]
|
||||
[Column(Unique = "uk_group_index, uk_group_index22")]
|
||||
public string group { get; set; }
|
||||
[Column(Unique = "uk_group_index11")]
|
||||
[Column(Unique = "uk_group_index")]
|
||||
public int index { get; set; }
|
||||
[Column(Unique = "uk_group_index222")]
|
||||
[Column(Unique = "uk_group_index22")]
|
||||
public string index22 { get; set; }
|
||||
}
|
||||
|
||||
|
@ -56,11 +56,11 @@ namespace FreeSql.Tests.SqlServer {
|
||||
[Column(Unique = "uk_phone")]
|
||||
public string phone { get; set; }
|
||||
|
||||
[Column(Unique = "uk_group_index")]
|
||||
[Column(Unique = "uk_group_index, uk_group_index22")]
|
||||
public string group { get; set; }
|
||||
[Column(Unique = "uk_group_index11")]
|
||||
[Column(Unique = "uk_group_index")]
|
||||
public int index { get; set; }
|
||||
[Column(Unique = "uk_group_index222")]
|
||||
[Column(Unique = "uk_group_index22")]
|
||||
public string index22 { get; set; }
|
||||
}
|
||||
|
||||
|
@ -45,11 +45,11 @@ namespace FreeSql.Tests.Sqlite {
|
||||
[Column(Unique = "uk_phone")]
|
||||
public string phone { get; set; }
|
||||
|
||||
[Column(Unique = "uk_group_index")]
|
||||
[Column(Unique = "uk_group_index, uk_group_index22")]
|
||||
public string group { get; set; }
|
||||
[Column(Unique = "uk_group_index111")]
|
||||
[Column(Unique = "uk_group_index")]
|
||||
public int index { get; set; }
|
||||
[Column(Unique = "uk_group_index222")]
|
||||
[Column(Unique = "uk_group_index22")]
|
||||
public string index22 { get; set; }
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace FreeSql.DataAnnotations {
|
||||
public class ColumnAttribute : Attribute {
|
||||
@ -38,10 +39,30 @@ namespace FreeSql.DataAnnotations {
|
||||
/// </summary>
|
||||
public bool IsVersion { get => _IsVersion ?? false; set => _IsVersion = value; }
|
||||
|
||||
internal string[] _Uniques;
|
||||
/// <summary>
|
||||
/// 唯一键,多个属性指定相同的标识,代表联合键
|
||||
/// 唯一键,在多个属性指定相同的标识,代表联合键;可使用逗号分割多个 UniqueKey 名。
|
||||
/// </summary>
|
||||
public string Unique { get; set; }
|
||||
public string Unique {
|
||||
get => _Uniques == null ? null : string.Join(", ", _Uniques);
|
||||
set {
|
||||
if (string.IsNullOrEmpty(value)) {
|
||||
_Uniques = null;
|
||||
return;
|
||||
}
|
||||
var val = value?.Trim(' ', '\t', ',');
|
||||
if (string.IsNullOrEmpty(val)) {
|
||||
_Uniques = null;
|
||||
return;
|
||||
}
|
||||
var arr = val.Split(',').Select(a => a.Trim(' ', '\t').Trim()).Where(a => !string.IsNullOrEmpty(a)).ToArray();
|
||||
if (arr.Any() == false) {
|
||||
_Uniques = null;
|
||||
return;
|
||||
}
|
||||
_Uniques = arr;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 数据库默认值
|
||||
/// </summary>
|
||||
|
@ -66,7 +66,7 @@ namespace FreeSql.DataAnnotations {
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// 唯一键,多个属性指定相同的标识,代表联合键
|
||||
/// 唯一键,在多个属性指定相同的标识,代表联合键;可使用逗号分割多个 UniqueKey 名。
|
||||
/// </summary>
|
||||
/// <param name="value">标识</param>
|
||||
/// <returns></returns>
|
||||
|
@ -46,7 +46,7 @@
|
||||
</member>
|
||||
<member name="P:FreeSql.DataAnnotations.ColumnAttribute.Unique">
|
||||
<summary>
|
||||
唯一键,多个属性指定相同的标识,代表联合键
|
||||
唯一键,在多个属性指定相同的标识,代表联合键;可使用逗号分割多个 UniqueKey 名。
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.DataAnnotations.ColumnAttribute.DbDefautValue">
|
||||
@ -101,7 +101,7 @@
|
||||
</member>
|
||||
<member name="M:FreeSql.DataAnnotations.ColumnFluent.Unique(System.String)">
|
||||
<summary>
|
||||
唯一键,多个属性指定相同的标识,代表联合键
|
||||
唯一键,在多个属性指定相同的标识,代表联合键;可使用逗号分割多个 UniqueKey 名。
|
||||
</summary>
|
||||
<param name="value">标识</param>
|
||||
<returns></returns>
|
||||
|
@ -101,7 +101,7 @@ namespace FreeSql.Internal {
|
||||
if (trycol._IsNullable != null) attr._IsNullable = trycol.IsNullable;
|
||||
if (trycol._IsIgnore != null) attr._IsIgnore = trycol.IsIgnore;
|
||||
if (trycol._IsVersion != null) attr._IsVersion = trycol.IsVersion;
|
||||
if (!string.IsNullOrEmpty(trycol.Unique)) attr.Unique = trycol.Unique;
|
||||
if (trycol._Uniques != null) attr._Uniques = trycol._Uniques;
|
||||
if (trycol.MapType != null) attr.MapType = trycol.MapType;
|
||||
if (trycol.DbDefautValue != null) attr.DbDefautValue = trycol.DbDefautValue;
|
||||
}
|
||||
@ -117,7 +117,7 @@ namespace FreeSql.Internal {
|
||||
if (tryattr._IsNullable != null) attr._IsNullable = tryattr.IsNullable;
|
||||
if (tryattr._IsIgnore != null) attr._IsIgnore = tryattr.IsIgnore;
|
||||
if (tryattr._IsVersion != null) attr._IsVersion = tryattr.IsVersion;
|
||||
if (!string.IsNullOrEmpty(tryattr.Unique)) attr.Unique = tryattr.Unique;
|
||||
if (tryattr._Uniques != null) attr._Uniques = tryattr._Uniques;
|
||||
if (tryattr.MapType != null) attr.MapType = tryattr.MapType;
|
||||
if (tryattr.DbDefautValue != null) attr.DbDefautValue = tryattr.DbDefautValue;
|
||||
}
|
||||
@ -130,7 +130,7 @@ namespace FreeSql.Internal {
|
||||
if (attr._IsNullable != null) ret = attr;
|
||||
if (attr._IsIgnore != null) ret = attr;
|
||||
if (attr._IsVersion != null) ret = attr;
|
||||
if (!string.IsNullOrEmpty(attr.Unique)) ret = attr;
|
||||
if (attr._Uniques != null) ret = attr;
|
||||
if (attr.MapType != null) ret = attr;
|
||||
if (attr.DbDefautValue != null) ret = attr;
|
||||
if (ret != null && ret.MapType == null) ret.MapType = proto.PropertyType;
|
||||
|
@ -91,11 +91,11 @@ namespace FreeSql.Internal {
|
||||
if (string.IsNullOrEmpty(colattr.Name)) colattr.Name = p.Name;
|
||||
if (common.CodeFirst.IsSyncStructureToLower) {
|
||||
colattr.Name = colattr.Name.ToLower();
|
||||
if (!string.IsNullOrEmpty(colattr.Unique)) colattr.Unique = colattr.Unique.ToLower();
|
||||
colattr.Unique = colattr.Unique?.ToLower();
|
||||
}
|
||||
if (common.CodeFirst.IsSyncStructureToUpper) {
|
||||
colattr.Name = colattr.Name.ToUpper();
|
||||
if (!string.IsNullOrEmpty(colattr.Unique)) colattr.Unique = colattr.Unique.ToUpper();
|
||||
colattr.Unique = colattr.Unique?.ToUpper();
|
||||
}
|
||||
|
||||
if ((colattr.IsNullable != true || colattr.IsIdentity == true || colattr.IsPrimary == true) && colattr.DbType.Contains("NOT NULL") == false) {
|
||||
@ -179,7 +179,8 @@ namespace FreeSql.Internal {
|
||||
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;
|
||||
if (trycol.Attribute._Uniques?.Contains(dbuk.Key) != true)
|
||||
trycol.Attribute.Unique += $"," + dbuk.Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -188,8 +189,8 @@ namespace FreeSql.Internal {
|
||||
} 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)).Select(a => a.Attribute.Unique).Distinct()
|
||||
.ToDictionary(a => a, a => trytb.Columns.Values.Where(b => b.Attribute.Unique == a).ToList());
|
||||
var allunique = trytb.Columns.Values.Where(a => a.Attribute._Uniques != null).SelectMany(a => a.Attribute._Uniques).Distinct();
|
||||
trytb.Uniques = allunique.ToDictionary(a => a, a => trytb.Columns.Values.Where(b => b.Attribute._Uniques != null && b.Attribute._Uniques.Contains(a)).ToList());
|
||||
tbc.AddOrUpdate(entity, trytb, (oldkey, oldval) => trytb);
|
||||
|
||||
#region 查找导航属性的关系、virtual 属性延时加载,动态产生新的重写类
|
||||
|
Loading…
x
Reference in New Issue
Block a user