mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 增加 Column 特性 RereadSql 重读功能;
This commit is contained in:
@ -115,5 +115,16 @@ namespace FreeSql.DataAnnotations
|
||||
/// decimal/numeric 类型的小数位长度
|
||||
/// </summary>
|
||||
public int Scale { get => _Scale ?? 0; set => _Scale = value; }
|
||||
|
||||
///// <summary>
|
||||
///// 写入格式化,比如 geography::STGeomFromText({0},4236)
|
||||
///// </summary>
|
||||
//public string AuditWriteSql { get; set; }
|
||||
/// <summary>
|
||||
/// 设置重读功能<para></para>
|
||||
/// [Column(RereadSql = "{0}.STAsText()")]<para></para>
|
||||
/// 查询:SELECT a.[id], a.[geo].STAsText() FROM table a
|
||||
/// </summary>
|
||||
public string RereadSql { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -115,6 +115,13 @@
|
||||
decimal/numeric 类型的小数位长度
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.DataAnnotations.ColumnAttribute.RereadSql">
|
||||
<summary>
|
||||
设置重读功能<para></para>
|
||||
[Column(RereadSql = "{0}.STAsText()")]<para></para>
|
||||
查询:SELECT a.[id], a.[geo].STAsText() FROM table a
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.DataAnnotations.ColumnFluent.Name(System.String)">
|
||||
<summary>
|
||||
数据库列名
|
||||
|
@ -131,7 +131,7 @@ namespace FreeSql.Internal
|
||||
CsType = map[idx].Column.CsType,
|
||||
MapType = map[idx].Column.Attribute.MapType
|
||||
};
|
||||
field.Append(", ").Append(_common.QuoteReadColumn(child.CsType, child.MapType, child.DbField));
|
||||
field.Append(", ").Append(_common.QuoteReadColumn(map[idx].Column, child.CsType, child.MapType, child.DbField));
|
||||
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||
parent.Childs.Add(child);
|
||||
}
|
||||
|
@ -415,7 +415,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
if (tbiindex > 0 && colidx == 0) field.Append("\r\n");
|
||||
}
|
||||
var quoteName = _commonUtils.QuoteSqlName(col.Attribute.Name);
|
||||
field.Append(_commonUtils.QuoteReadColumn(col.CsType, col.Attribute.MapType, $"{tbi.Alias}.{quoteName}"));
|
||||
field.Append(_commonUtils.QuoteReadColumn(col, col.CsType, col.Attribute.MapType, $"{tbi.Alias}.{quoteName}"));
|
||||
++index;
|
||||
if (dicfield.ContainsKey(quoteName)) field.Append(_commonUtils.FieldAsAlias($"as{index}"));
|
||||
else dicfield.Add(quoteName, true);
|
||||
@ -555,7 +555,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{ //普通字段
|
||||
if (index > 0) field.Append(", ");
|
||||
var quoteName = _commonUtils.QuoteSqlName(col.Attribute.Name);
|
||||
field.Append(_commonUtils.QuoteReadColumn(col.CsType, col.Attribute.MapType, $"{tb.Alias}.{quoteName}"));
|
||||
field.Append(_commonUtils.QuoteReadColumn(col, col.CsType, col.Attribute.MapType, $"{tb.Alias}.{quoteName}"));
|
||||
++index;
|
||||
if (dicfield.ContainsKey(quoteName)) field.Append(_commonUtils.FieldAsAlias($"as{index}"));
|
||||
else dicfield.Add(quoteName, true);
|
||||
@ -578,7 +578,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (index > 0) field.Append(", ");
|
||||
var quoteName = _commonUtils.QuoteSqlName(col2.Attribute.Name);
|
||||
field.Append(_commonUtils.QuoteReadColumn(col2.CsType, col2.Attribute.MapType, $"{tb2.Alias}.{quoteName}"));
|
||||
field.Append(_commonUtils.QuoteReadColumn(col2, col2.CsType, col2.Attribute.MapType, $"{tb2.Alias}.{quoteName}"));
|
||||
++index;
|
||||
++otherindex;
|
||||
if (dicfield.ContainsKey(quoteName)) field.Append(_commonUtils.FieldAsAlias($"as{index}"));
|
||||
|
@ -1025,7 +1025,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
Property = tbrefMid.Properties[col.CsName]
|
||||
};
|
||||
read.Childs.Add(child);
|
||||
field.Append(", ").Append(_commonUtils.QuoteReadColumn(child.CsType, child.MapType, child.DbField));
|
||||
field.Append(", ").Append(_commonUtils.QuoteReadColumn(col, child.CsType, child.MapType, child.DbField));
|
||||
}
|
||||
otherData = new ReadAnonymousTypeAfInfo(read, field.ToString());
|
||||
}
|
||||
|
@ -53,7 +53,14 @@ namespace FreeSql.Internal
|
||||
public abstract string Now { get; }
|
||||
public abstract string NowUtc { get; }
|
||||
public abstract string QuoteWriteParamter(Type type, string paramterName);
|
||||
public abstract string QuoteReadColumn(Type type, Type mapType, string columnName);
|
||||
protected abstract string QuoteReadColumnAdapter(Type type, Type mapType, string columnName);
|
||||
public string QuoteReadColumn(ColumnInfo col, Type type, Type mapType, string columnName)
|
||||
{
|
||||
var result = QuoteReadColumnAdapter(type, mapType, columnName);
|
||||
if (string.IsNullOrWhiteSpace(col?.Attribute.RereadSql) == false)
|
||||
return string.Format(col.Attribute.RereadSql, result);
|
||||
return result;
|
||||
}
|
||||
public virtual string FieldAsAlias(string alias) => $" {alias}";
|
||||
public virtual string IIF(string test, string ifTrue, string ifElse) => $"case when {test} then {ifTrue} else {ifElse} end";
|
||||
public static string BytesSqlRaw(byte[] bytes)
|
||||
|
Reference in New Issue
Block a user