- 增加 Column 特性 RereadSql 重读功能;

This commit is contained in:
2881099
2020-12-21 20:31:16 +08:00
parent 1effade3b1
commit 76e8b3efce
61 changed files with 143 additions and 118 deletions

View File

@ -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);
}

View File

@ -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}"));

View File

@ -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());
}

View File

@ -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)