mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-20 04:48:16 +08:00
- 优化 RereadSql 支持表的其他字段使用;#1655
This commit is contained in:
@ -126,6 +126,7 @@ namespace FreeSql.DataAnnotations
|
||||
/// <summary>
|
||||
/// 重读功能<para></para>
|
||||
/// 比如:[Column(RereadSql = "{0}.STAsText()")]<para></para>
|
||||
/// 或者:[Column(RereadSql = "{geo}.STAsText()")]<para></para>
|
||||
/// 查询:SELECT a.[id], a.[geo].STAsText() FROM [table] a
|
||||
/// </summary>
|
||||
public string RereadSql { get; set; }
|
||||
|
@ -206,6 +206,7 @@ namespace FreeSql.DataAnnotations
|
||||
/// <summary>
|
||||
/// 重读功能<para></para>
|
||||
/// 比如:[Column(RereadSql = "{0}.STAsText()")]<para></para>
|
||||
/// 或者:[Column(RereadSql = "{geo}.STAsText()")]<para></para>
|
||||
/// 查询:SELECT a.[id], a.[geo].STAsText() FROM [table] a
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
|
@ -127,6 +127,7 @@
|
||||
<summary>
|
||||
重读功能<para></para>
|
||||
比如:[Column(RereadSql = "{0}.STAsText()")]<para></para>
|
||||
或者:[Column(RereadSql = "{geo}.STAsText()")]<para></para>
|
||||
查询:SELECT a.[id], a.[geo].STAsText() FROM [table] a
|
||||
</summary>
|
||||
</member>
|
||||
@ -260,6 +261,7 @@
|
||||
<summary>
|
||||
重读功能<para></para>
|
||||
比如:[Column(RereadSql = "{0}.STAsText()")]<para></para>
|
||||
或者:[Column(RereadSql = "{geo}.STAsText()")]<para></para>
|
||||
查询:SELECT a.[id], a.[geo].STAsText() FROM [table] a
|
||||
</summary>
|
||||
<param name="value"></param>
|
||||
|
@ -75,7 +75,18 @@ namespace FreeSql.Internal
|
||||
{
|
||||
var result = QuoteReadColumnAdapter(col.CsType, col.Attribute.MapType, columnName);
|
||||
if (string.IsNullOrWhiteSpace(col?.Attribute.RereadSql) == false)
|
||||
return string.Format(col.Attribute.RereadSql, result);
|
||||
{
|
||||
var tableAlias = columnName.Replace(QuoteSqlName(col.Attribute.Name), "");
|
||||
var rereadSql = Regex.Replace(col.Attribute.RereadSql, @"\{([_\w][_\w\d]+)\}", rm =>
|
||||
{
|
||||
if (col.Table.ColumnsByCs.TryGetValue(rm.Groups[1].Value, out var trycol))
|
||||
return $"{tableAlias}{QuoteSqlName(trycol.Attribute.Name)}";
|
||||
else if (col.Table.Columns.TryGetValue(rm.Groups[1].Value, out trycol))
|
||||
return $"{tableAlias}{QuoteSqlName(trycol.Attribute.Name)}";
|
||||
return rm.Groups[0].Value;
|
||||
});
|
||||
return string.Format(rereadSql, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public virtual string FieldAsAlias(string alias) => $" {alias}";
|
||||
|
Reference in New Issue
Block a user