mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
test RereadSql/RewriteSql #614
This commit is contained in:
@ -195,8 +195,14 @@ namespace FreeSql.Internal
|
||||
return false;
|
||||
}
|
||||
if (parent.CsType == null) parent.CsType = exp.Type;
|
||||
parent.DbField = ExpressionLambdaToSql(exp, getTSC());
|
||||
field.Append(", ").Append(parent.DbField);
|
||||
var pdbfield = parent.DbField = ExpressionLambdaToSql(exp, getTSC());
|
||||
if (parent.MapType == null || _tables?.Any(a => a.Table.IsRereadSql) == true)
|
||||
{
|
||||
var findcol = SearchColumnByField(_tables, null, parent.DbField);
|
||||
if (parent.MapType == null) parent.MapType = findcol?.Attribute.MapType ?? exp.Type;
|
||||
if (findcol != null) pdbfield = _common.RereadColumn(findcol, pdbfield);
|
||||
}
|
||||
field.Append(", ").Append(pdbfield);
|
||||
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false)
|
||||
{
|
||||
@ -204,7 +210,6 @@ namespace FreeSql.Internal
|
||||
if (parent.DbField.EndsWith(csname, StringComparison.CurrentCultureIgnoreCase) == false) //DbField 和 CsName 相同的时候,不处理
|
||||
field.Append(_common.FieldAsAlias(csname));
|
||||
}
|
||||
if (parent.MapType == null) parent.MapType = SearchColumnByField(_tables, null, parent.DbField)?.Attribute.MapType ?? exp.Type;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
@ -254,7 +259,7 @@ namespace FreeSql.Internal
|
||||
else
|
||||
{
|
||||
child.DbField = $"{dtTb.Alias}.{_common.QuoteSqlName(trydtocol.Attribute.Name)}";
|
||||
field.Append(", ").Append(child.DbField);
|
||||
field.Append(", ").Append(_common.RereadColumn(trydtocol, child.DbField));
|
||||
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||
}
|
||||
break;
|
||||
@ -336,7 +341,7 @@ namespace FreeSql.Internal
|
||||
ReadAnonymousField(_tables, field, child, ref index, Expression.Property(dtTb.Parameter, dtTb.Table.Properties[trydtocol.CsName]), select, diymemexp, whereGlobalFilter, findIncludeMany, isAllDtoMap);
|
||||
else
|
||||
{
|
||||
child.DbField = $"{dtTb.Alias}.{_common.QuoteSqlName(trydtocol.Attribute.Name)}";
|
||||
child.DbField = _common.RereadColumn(trydtocol, $"{dtTb.Alias}.{_common.QuoteSqlName(trydtocol.Attribute.Name)}");
|
||||
field.Append(", ").Append(child.DbField);
|
||||
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||
}
|
||||
|
@ -698,7 +698,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(_paramsSource, "u", col, col.Attribute.MapType, val) :
|
||||
_commonUtils.QuoteWriteParamterAdapter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"p_{_paramsSource.Count}"));
|
||||
_set.Append(_commonUtils.RewriteColumn(col, colsql));
|
||||
sb.Append(_commonUtils.RewriteColumn(col, colsql));
|
||||
if (_noneParameter == false)
|
||||
_commonUtils.AppendParamter(_paramsSource, null, col, col.Attribute.MapType, val);
|
||||
}
|
||||
@ -742,7 +742,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(_paramsSource, "u", col, col.Attribute.MapType, val) :
|
||||
_commonUtils.QuoteWriteParamterAdapter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"p_{_paramsSource.Count}"));
|
||||
_set.Append(_commonUtils.RewriteColumn(col, colsql));
|
||||
cwsb.Append(_commonUtils.RewriteColumn(col, colsql));
|
||||
if (_noneParameter == false)
|
||||
_commonUtils.AppendParamter(_paramsSource, null, col, col.Attribute.MapType, val);
|
||||
if (val == null || val == DBNull.Value) nulls++;
|
||||
|
@ -57,7 +57,7 @@ namespace FreeSql.Internal
|
||||
public string RewriteColumn(ColumnInfo col, string sql)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(col?.Attribute.RewriteSql) == false)
|
||||
return string.Format(col.Attribute.RereadSql, sql);
|
||||
return string.Format(col.Attribute.RewriteSql, sql);
|
||||
return sql;
|
||||
}
|
||||
public string RereadColumn(ColumnInfo col, string columnName)
|
||||
@ -170,6 +170,8 @@ namespace FreeSql.Internal
|
||||
if (!string.IsNullOrEmpty(trycol.InsertValueSql)) attr.InsertValueSql = trycol.InsertValueSql;
|
||||
if (trycol._Precision != null) attr.Precision = trycol.Precision;
|
||||
if (trycol._Scale != null) attr.Scale = trycol.Scale;
|
||||
if (!string.IsNullOrEmpty(trycol.RewriteSql)) attr.RewriteSql = trycol.RewriteSql;
|
||||
if (!string.IsNullOrEmpty(trycol.RereadSql)) attr.RereadSql = trycol.RereadSql;
|
||||
}
|
||||
var attrs = proto.GetCustomAttributes(typeof(ColumnAttribute), false);
|
||||
foreach (var tryattrobj in attrs)
|
||||
@ -193,6 +195,8 @@ namespace FreeSql.Internal
|
||||
if (!string.IsNullOrEmpty(tryattr.InsertValueSql)) attr.InsertValueSql = tryattr.InsertValueSql;
|
||||
if (tryattr._Precision != null) attr.Precision = tryattr.Precision;
|
||||
if (tryattr._Scale != null) attr.Scale = tryattr.Scale;
|
||||
if (!string.IsNullOrEmpty(tryattr.RewriteSql)) attr.RewriteSql = tryattr.RewriteSql;
|
||||
if (!string.IsNullOrEmpty(tryattr.RereadSql)) attr.RereadSql = tryattr.RereadSql;
|
||||
}
|
||||
ColumnAttribute ret = null;
|
||||
if (!string.IsNullOrEmpty(attr.Name)) ret = attr;
|
||||
@ -212,6 +216,8 @@ namespace FreeSql.Internal
|
||||
if (!string.IsNullOrEmpty(attr.InsertValueSql)) ret = attr;
|
||||
if (attr._Precision != null) ret = attr;
|
||||
if (attr._Scale != null) ret = attr;
|
||||
if (!string.IsNullOrEmpty(attr.RewriteSql)) ret = attr;
|
||||
if (!string.IsNullOrEmpty(attr.RereadSql)) ret = attr;
|
||||
if (ret != null && ret.MapType == null) ret.MapType = proto.PropertyType;
|
||||
return ret;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ namespace FreeSql.Internal.Model
|
||||
public string DbOldName { get; set; }
|
||||
public bool DisableSyncStructure { get; set; }
|
||||
public string Comment { get; internal set; }
|
||||
public bool IsRereadSql { get; internal set; }
|
||||
|
||||
public ColumnInfo VersionColumn { get; set; }
|
||||
|
||||
|
@ -495,6 +495,7 @@ namespace FreeSql.Internal
|
||||
col.DbPrecision = (byte)size;
|
||||
col.DbScale = scale;
|
||||
}
|
||||
trytb.IsRereadSql = trytb.Columns.Where(a => string.IsNullOrWhiteSpace(a.Value.Attribute.RereadSql) == false).Any();
|
||||
tbc.AddOrUpdate(entity, trytb, (oldkey, oldval) => trytb);
|
||||
|
||||
#region 查找导航属性的关系、virtual 属性延时加载,动态产生新的重写类
|
||||
|
Reference in New Issue
Block a user