mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 优化 RereadSql 支持表的其他字段使用;#1655
This commit is contained in:
parent
448b25c479
commit
7115b68871
@ -600,6 +600,21 @@ namespace base_entity
|
||||
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
||||
#endregion
|
||||
|
||||
var x01sql01 = fsql.Select<Main1>()
|
||||
.Include(a => a.Test1)
|
||||
.Include(a => a.Test2)
|
||||
.Include(a => a.Test3)
|
||||
.ToSql();
|
||||
|
||||
var txxx01 = fsql.Select<User1>()
|
||||
.WhereDynamicFilter(new DynamicFilterInfo
|
||||
{
|
||||
Field = nameof(User1.CreateTime),
|
||||
Operator = DynamicFilterOperator.DateRange,
|
||||
Value = $"{DateTime.MinValue.ToString("yyyy-MM-dd")},{DateTime.MinValue.ToString("yyyy-MM-dd")}"
|
||||
})
|
||||
.ToSql();
|
||||
|
||||
var updatejoin031sql = fsql.Update<User1>()
|
||||
.Join<UserGroup>(fsql.Select<UserGroup>().Where(a => a.GroupName == "xxx"), (a, b) => a.GroupId == b.Id)
|
||||
.AsTable("t1", null)
|
||||
@ -2951,3 +2966,29 @@ public class B11
|
||||
public string Name { get; set; }
|
||||
public A11 a { get; set; }
|
||||
}
|
||||
public class Main1
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
public long Test1Id { get; set; }
|
||||
|
||||
public long Test2Id { get; set; }
|
||||
|
||||
public long Test3Id { get; set; }
|
||||
|
||||
public virtual Test2 Test1 { get; set; }
|
||||
|
||||
public virtual Test2 Test2 { get; set; }
|
||||
|
||||
public virtual Test2 Test3 { get; set; }
|
||||
}
|
||||
|
||||
public class Test2
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
[Column(RereadSql = "IIF({IsEnabled} = 1, {0}, {0} + '-已停用')")]
|
||||
public string ItemName { get; set; }
|
||||
|
||||
public bool IsEnabled { get; set; }
|
||||
}
|
@ -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}";
|
||||
|
Loading…
x
Reference in New Issue
Block a user