mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 增加 创建表时指定字段位置,如:[Column(Position = 1],可为负数即反方向位置;
This commit is contained in:
@ -79,5 +79,17 @@ namespace FreeSql.DataAnnotations
|
||||
/// 类型映射,比如:可将 enum 属性映射成 typeof(string)
|
||||
/// </summary>
|
||||
public Type MapType { get; set; }
|
||||
}
|
||||
|
||||
internal short? _Position;
|
||||
/// <summary>
|
||||
/// 创建表时字段位置,规则如下:
|
||||
/// <para></para>
|
||||
/// >0时排前面,1,2,3...
|
||||
/// <para></para>
|
||||
/// =0时排中间(默认)
|
||||
/// <para></para>
|
||||
/// <0时排后面,...-3,-2,-1
|
||||
/// </summary>
|
||||
public short Position { get => _Position ?? 0; set => _Position = value; }
|
||||
}
|
||||
}
|
||||
|
@ -89,11 +89,28 @@ namespace FreeSql.DataAnnotations
|
||||
/// <summary>
|
||||
/// 类型映射,比如:可将 enum 属性映射成 typeof(string)
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public ColumnFluent MapType(Type type)
|
||||
public ColumnFluent MapType(Type value)
|
||||
{
|
||||
_column.MapType = type;
|
||||
_column.MapType = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建表时字段位置,规则如下:
|
||||
/// <para></para>
|
||||
/// >0时排前面
|
||||
/// <para></para>
|
||||
/// =0时排中间(默认)
|
||||
/// <para></para>
|
||||
/// <0时排后面
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public ColumnFluent Position(short value)
|
||||
{
|
||||
_column.Position = value;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,17 @@
|
||||
类型映射,比如:可将 enum 属性映射成 typeof(string)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.DataAnnotations.ColumnAttribute.Position">
|
||||
<summary>
|
||||
创建表时字段位置,规则如下:
|
||||
<para></para>
|
||||
>0时排前面,1,2,3...
|
||||
<para></para>
|
||||
=0时排中间(默认)
|
||||
<para></para>
|
||||
<0时排后面,...-3,-2,-1
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.DataAnnotations.ColumnFluent.Name(System.String)">
|
||||
<summary>
|
||||
数据库列名
|
||||
@ -110,7 +121,20 @@
|
||||
<summary>
|
||||
类型映射,比如:可将 enum 属性映射成 typeof(string)
|
||||
</summary>
|
||||
<param name="type"></param>
|
||||
<param name="value"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.DataAnnotations.ColumnFluent.Position(System.Int16)">
|
||||
<summary>
|
||||
创建表时字段位置,规则如下:
|
||||
<para></para>
|
||||
>0时排前面
|
||||
<para></para>
|
||||
=0时排中间(默认)
|
||||
<para></para>
|
||||
<0时排后面
|
||||
</summary>
|
||||
<param name="value"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:FreeSql.DataAnnotations.NavigateAttribute.Bind">
|
||||
|
@ -126,6 +126,7 @@ namespace FreeSql.Internal
|
||||
if (trycol._IsVersion != null) attr._IsVersion = trycol.IsVersion;
|
||||
if (trycol._Uniques != null) attr._Uniques = trycol._Uniques;
|
||||
if (trycol.MapType != null) attr.MapType = trycol.MapType;
|
||||
if (trycol._Position != null) attr._Position = trycol.Position;
|
||||
if (trycol.DbDefautValue != null) attr.DbDefautValue = trycol.DbDefautValue;
|
||||
}
|
||||
var attrs = proto.GetCustomAttributes(typeof(ColumnAttribute), false);
|
||||
@ -143,6 +144,7 @@ namespace FreeSql.Internal
|
||||
if (tryattr._IsVersion != null) attr._IsVersion = tryattr.IsVersion;
|
||||
if (tryattr._Uniques != null) attr._Uniques = tryattr._Uniques;
|
||||
if (tryattr.MapType != null) attr.MapType = tryattr.MapType;
|
||||
if (tryattr._Position != null) attr._Position = tryattr.Position;
|
||||
if (tryattr.DbDefautValue != null) attr.DbDefautValue = tryattr.DbDefautValue;
|
||||
}
|
||||
ColumnAttribute ret = null;
|
||||
@ -156,6 +158,7 @@ namespace FreeSql.Internal
|
||||
if (attr._IsVersion != null) ret = attr;
|
||||
if (attr._Uniques != null) ret = attr;
|
||||
if (attr.MapType != null) ret = attr;
|
||||
if (attr._Position != null) ret = attr;
|
||||
if (attr.DbDefautValue != null) ret = attr;
|
||||
if (ret != null && ret.MapType == null) ret.MapType = proto.PropertyType;
|
||||
return ret;
|
||||
|
@ -14,6 +14,7 @@ namespace FreeSql.Internal.Model
|
||||
public Dictionary<string, ColumnInfo> Columns { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
|
||||
public Dictionary<string, ColumnInfo> ColumnsByCs { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
|
||||
public Dictionary<string, ColumnInfo> ColumnsByCsIgnore { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
|
||||
public ColumnInfo[] ColumnsByPosition { get; set; }
|
||||
public ColumnInfo[] Primarys { get; set; }
|
||||
public Dictionary<string, List<ColumnInfo>> Uniques { get; set; }
|
||||
public string CsName { get; set; }
|
||||
|
@ -70,6 +70,7 @@ namespace FreeSql.Internal
|
||||
var propsLazy = new List<(PropertyInfo, bool, bool)>();
|
||||
var propsNavObjs = new List<PropertyInfo>();
|
||||
var propsComment = CommonUtils.GetProperyCommentBySummary(entity);
|
||||
var columnsList = new List<ColumnInfo>();
|
||||
foreach (var p in trytb.Properties.Values)
|
||||
{
|
||||
var setMethod = trytb.Type.GetMethod($"set_{p.Name}");
|
||||
@ -169,6 +170,7 @@ namespace FreeSql.Internal
|
||||
|
||||
trytb.Columns.Add(colattr.Name, col);
|
||||
trytb.ColumnsByCs.Add(p.Name, col);
|
||||
columnsList.Add(col);
|
||||
}
|
||||
trytb.VersionColumn = trytb.Columns.Values.Where(a => a.Attribute.IsVersion == true).LastOrDefault();
|
||||
if (trytb.VersionColumn != null)
|
||||
@ -241,6 +243,9 @@ namespace FreeSql.Internal
|
||||
}
|
||||
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());
|
||||
trytb.ColumnsByPosition = columnsList.Where(a => a.Attribute.Position > 0).OrderBy(a => a.Attribute.Position)
|
||||
.Concat(columnsList.Where(a => a.Attribute.Position == 0))
|
||||
.Concat(columnsList.Where(a => a.Attribute.Position < 0).OrderBy(a => a.Attribute.Position)).ToArray();
|
||||
tbc.AddOrUpdate(entity, trytb, (oldkey, oldval) => trytb);
|
||||
|
||||
#region 查找导航属性的关系、virtual 属性延时加载,动态产生新的重写类
|
||||
|
Reference in New Issue
Block a user