mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 增加 Column 特性 RewriteSql 重读功能;
This commit is contained in:
parent
76e8b3efce
commit
e5452ad43f
@ -512,14 +512,5 @@
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -116,14 +116,17 @@ namespace FreeSql.DataAnnotations
|
||||
/// </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
|
||||
/// 重写功能<para></para>
|
||||
/// 比如:[Column(RewriteSql = "geography::STGeomFromText({0},4236)")]<para></para>
|
||||
/// 插入:INSERT INTO [table]([geo]) VALUES(geography::STGeomFromText('...',4236))<para></para>
|
||||
/// 提示:更新也生效
|
||||
/// </summary>
|
||||
public string RewriteSql { 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,11 +115,19 @@
|
||||
decimal/numeric 类型的小数位长度
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.DataAnnotations.ColumnAttribute.RewriteSql">
|
||||
<summary>
|
||||
重写功能<para></para>
|
||||
比如:[Column(RewriteSql = "geography::STGeomFromText({0},4236)")]<para></para>
|
||||
插入:INSERT INTO [table]([geo]) VALUES(geography::STGeomFromText('...',4236))<para></para>
|
||||
提示:更新也生效
|
||||
</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
|
||||
重读功能<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)">
|
||||
|
@ -572,13 +572,12 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
object val = col.GetDbValue(d);
|
||||
if (val == null && col.Attribute.IsNullable == false) val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384
|
||||
if (_noneParameter)
|
||||
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val));
|
||||
else
|
||||
{
|
||||
sb.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}")));
|
||||
|
||||
var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val) :
|
||||
_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}"));
|
||||
sb.Append(_commonUtils.QuoteWriteColumn(col, colsql));
|
||||
if (_noneParameter == false)
|
||||
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}_{didx}", col, col.Attribute.MapType, val);
|
||||
}
|
||||
}
|
||||
++colidx2;
|
||||
}
|
||||
|
@ -434,15 +434,12 @@ namespace FreeSql.Internal.CommonProvider
|
||||
if (col.Attribute.MapType == col.CsType) val = value;
|
||||
else val = Utils.GetDataReaderValue(col.Attribute.MapType, value);
|
||||
_set.Append(", ").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ");
|
||||
if (_noneParameter)
|
||||
{
|
||||
_set.Append(_commonUtils.GetNoneParamaterSqlValue(_params, "u", col, col.Attribute.MapType, val));
|
||||
}
|
||||
else
|
||||
{
|
||||
_set.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, $"{_commonUtils.QuoteParamterName("p_")}{_params.Count}"));
|
||||
|
||||
var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(_params, "u", col, col.Attribute.MapType, val) :
|
||||
_commonUtils.QuoteWriteParamter(col.Attribute.MapType, $"{_commonUtils.QuoteParamterName("p_")}{_params.Count}");
|
||||
_set.Append(_commonUtils.QuoteWriteColumn(col, colsql));
|
||||
if (_noneParameter == false)
|
||||
_commonUtils.AppendParamter(_params, null, col, col.Attribute.MapType, val);
|
||||
}
|
||||
}
|
||||
public IUpdate<T1> Set<TMember>(Expression<Func<T1, TMember>> column, TMember value)
|
||||
{
|
||||
@ -698,13 +695,12 @@ namespace FreeSql.Internal.CommonProvider
|
||||
else
|
||||
{
|
||||
var val = col.GetDbValue(_source.First());
|
||||
if (_noneParameter)
|
||||
sb.Append(_commonUtils.GetNoneParamaterSqlValue(_paramsSource, "u", col, col.Attribute.MapType, val));
|
||||
else
|
||||
{
|
||||
sb.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"p_{_paramsSource.Count}")));
|
||||
|
||||
var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(_paramsSource, "u", col, col.Attribute.MapType, val) :
|
||||
_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"p_{_paramsSource.Count}"));
|
||||
_set.Append(_commonUtils.QuoteWriteColumn(col, colsql));
|
||||
if (_noneParameter == false)
|
||||
_commonUtils.AppendParamter(_paramsSource, null, col, col.Attribute.MapType, val);
|
||||
}
|
||||
}
|
||||
++colidx;
|
||||
}
|
||||
@ -743,13 +739,12 @@ namespace FreeSql.Internal.CommonProvider
|
||||
ToSqlWhen(cwsb, _table.Primarys, d);
|
||||
cwsb.Append(" THEN ");
|
||||
var val = col.GetDbValue(d);
|
||||
if (_noneParameter)
|
||||
cwsb.Append(_commonUtils.GetNoneParamaterSqlValue(_paramsSource, "u", col, col.Attribute.MapType, val));
|
||||
else
|
||||
{
|
||||
cwsb.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"p_{_paramsSource.Count}")));
|
||||
|
||||
var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(_paramsSource, "u", col, col.Attribute.MapType, val) :
|
||||
_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"p_{_paramsSource.Count}"));
|
||||
_set.Append(_commonUtils.QuoteWriteColumn(col, colsql));
|
||||
if (_noneParameter == false)
|
||||
_commonUtils.AppendParamter(_paramsSource, null, col, col.Attribute.MapType, val);
|
||||
}
|
||||
if (val == null || val == DBNull.Value) nulls++;
|
||||
}
|
||||
cwsb.Append(" END");
|
||||
|
@ -54,6 +54,12 @@ namespace FreeSql.Internal
|
||||
public abstract string NowUtc { get; }
|
||||
public abstract string QuoteWriteParamter(Type type, string paramterName);
|
||||
protected abstract string QuoteReadColumnAdapter(Type type, Type mapType, string columnName);
|
||||
public string QuoteWriteColumn(ColumnInfo col, string sql)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(col?.Attribute.RewriteSql) == false)
|
||||
return string.Format(col.Attribute.RereadSql, sql);
|
||||
return sql;
|
||||
}
|
||||
public string QuoteReadColumn(ColumnInfo col, Type type, Type mapType, string columnName)
|
||||
{
|
||||
var result = QuoteReadColumnAdapter(type, mapType, columnName);
|
||||
|
@ -73,13 +73,12 @@ namespace FreeSql.Dameng.Curd
|
||||
{
|
||||
object val = col.GetDbValue(d);
|
||||
if (val == null && col.Attribute.IsNullable == false) val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384
|
||||
if (_noneParameter)
|
||||
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val));
|
||||
else
|
||||
{
|
||||
sb.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}")));
|
||||
|
||||
var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val) :
|
||||
_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}"));
|
||||
sb.Append(_commonUtils.QuoteWriteColumn(col, colsql));
|
||||
if (_noneParameter == false)
|
||||
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}_{didx}", col, col.Attribute.MapType, val);
|
||||
}
|
||||
}
|
||||
++colidx2;
|
||||
}
|
||||
|
@ -69,13 +69,12 @@ namespace FreeSql.Odbc.Dameng
|
||||
{
|
||||
object val = col.GetDbValue(d);
|
||||
if (val == null && col.Attribute.IsNullable == false) val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384
|
||||
if (_noneParameter)
|
||||
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val));
|
||||
else
|
||||
{
|
||||
sb.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}")));
|
||||
|
||||
var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val) :
|
||||
_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}"));
|
||||
sb.Append(_commonUtils.QuoteWriteColumn(col, colsql));
|
||||
if (_noneParameter == false)
|
||||
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}_{didx}", col, col.Attribute.MapType, val);
|
||||
}
|
||||
}
|
||||
++colidx2;
|
||||
}
|
||||
|
@ -69,13 +69,12 @@ namespace FreeSql.Odbc.Oracle
|
||||
{
|
||||
object val = col.GetDbValue(d);
|
||||
if (val == null && col.Attribute.IsNullable == false) val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384
|
||||
if (_noneParameter)
|
||||
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val));
|
||||
else
|
||||
{
|
||||
sb.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}")));
|
||||
|
||||
var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val) :
|
||||
_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}"));
|
||||
sb.Append(_commonUtils.QuoteWriteColumn(col, colsql));
|
||||
if (_noneParameter == false)
|
||||
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}_{didx}", col, col.Attribute.MapType, val);
|
||||
}
|
||||
}
|
||||
++colidx2;
|
||||
}
|
||||
|
@ -82,13 +82,12 @@ namespace FreeSql.Oracle.Curd
|
||||
{
|
||||
object val = col.GetDbValue(d);
|
||||
if (val == null && col.Attribute.IsNullable == false) val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384
|
||||
if (_noneParameter)
|
||||
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val));
|
||||
else
|
||||
{
|
||||
sb.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}")));
|
||||
|
||||
var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val) :
|
||||
_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}"));
|
||||
sb.Append(_commonUtils.QuoteWriteColumn(col, colsql));
|
||||
if (_noneParameter == false)
|
||||
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}_{didx}", col, col.Attribute.MapType, val);
|
||||
}
|
||||
}
|
||||
if (didx == 0) sb.Append(" as ").Append(col.Attribute.Name);
|
||||
++colidx2;
|
||||
@ -147,13 +146,12 @@ namespace FreeSql.Oracle.Curd
|
||||
{
|
||||
object val = col.GetDbValue(d);
|
||||
if (val == null && col.Attribute.IsNullable == false) val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384
|
||||
if (_noneParameter)
|
||||
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val));
|
||||
else
|
||||
{
|
||||
sb.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}")));
|
||||
|
||||
var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val) :
|
||||
_commonUtils.QuoteWriteParamter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}"));
|
||||
sb.Append(_commonUtils.QuoteWriteColumn(col, colsql));
|
||||
if (_noneParameter == false)
|
||||
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}_{didx}", col, col.Attribute.MapType, val);
|
||||
}
|
||||
}
|
||||
++colidx2;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user