mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- 修复 MySql AsTreeCte 别名问题;
This commit is contained in:
parent
7093ca7eec
commit
4d8f4ce08d
@ -608,10 +608,33 @@ namespace base_entity
|
|||||||
.UseGenerateCommandParameterWithLambda(true)
|
.UseGenerateCommandParameterWithLambda(true)
|
||||||
.Build();
|
.Build();
|
||||||
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
fsql.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||||
|
var repoxx = fsql.GetRepository<VM_District_Child>();
|
||||||
|
repoxx.DbContextOptions.EnableCascadeSave = true;
|
||||||
|
repoxx.DbContextOptions.NoneParameter = true;
|
||||||
|
repoxx.Insert(new VM_District_Child
|
||||||
|
{
|
||||||
|
Code = "100000",
|
||||||
|
Name = "中国",
|
||||||
|
Childs = new List<VM_District_Child>(new[] {
|
||||||
|
new VM_District_Child
|
||||||
|
{
|
||||||
|
Code = "110000",
|
||||||
|
Name = "北京",
|
||||||
|
Childs = new List<VM_District_Child>(new[] {
|
||||||
|
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||||
|
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
var ttre1 = fsql.Select<VM_District_Child>().Where(a => a.Name == "中国")
|
||||||
|
.AsTreeCte(pathSelector: a => $"[{a.Name}]{a.Code}", pathSeparator: "=>")
|
||||||
|
.OrderBy(a => a.Code).ToTreeList(); ;
|
||||||
|
|
||||||
var list111222 = fsql.Select<OrderLine, Product>()
|
var list111222 = fsql.Select<OrderLine, Product>()
|
||||||
.InnerJoin((l, p) => l.ProductId == p.ID)
|
.InnerJoin((l, p) => l.ProductId == p.ID)
|
||||||
.GroupBy((l, p) => new { p.ID, ShopType = l.ShopType ?? 0 })
|
.GroupBy((l, p) => new { p.ID, ShopType = l.ShopType ?? 0 })
|
||||||
.WithTempQuery(a => new
|
.WithTempQuery(a => new
|
||||||
@ -3103,3 +3126,33 @@ public partial class Product
|
|||||||
public string Model { get; set; }
|
public string Model { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Table(Name = "D1_District")]
|
||||||
|
public class BaseDistrict
|
||||||
|
{
|
||||||
|
[Column(IsPrimary = true, StringLength = 6)]
|
||||||
|
public string Code { get; set; }
|
||||||
|
|
||||||
|
[Column(StringLength = 20, IsNullable = false)]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[Column(StringLength = 6)]
|
||||||
|
public virtual string ParentCode { get; set; }
|
||||||
|
|
||||||
|
public int testint { get; set; }
|
||||||
|
}
|
||||||
|
[Table(Name = "D1_District")]
|
||||||
|
public class VM_District_Child : BaseDistrict
|
||||||
|
{
|
||||||
|
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||||
|
|
||||||
|
[Navigate(nameof(ParentCode))]
|
||||||
|
public List<VM_District_Child> Childs { get; set; }
|
||||||
|
}
|
||||||
|
[Table(Name = "D1_District")]
|
||||||
|
public class VM_District_Parent : BaseDistrict
|
||||||
|
{
|
||||||
|
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||||
|
|
||||||
|
[Navigate(nameof(ParentCode))]
|
||||||
|
public VM_District_Parent Parent { get; set; }
|
||||||
|
}
|
@ -750,17 +750,20 @@ JOIN {select._commonUtils.QuoteSqlName(tbDbName)} a ON cte_tbc.cte_id = a.{selec
|
|||||||
case DataType.CustomSqlServer:
|
case DataType.CustomSqlServer:
|
||||||
case DataType.Firebird:
|
case DataType.Firebird:
|
||||||
case DataType.ClickHouse:
|
case DataType.ClickHouse:
|
||||||
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule, Expression.Call(typeof(Convert).GetMethod("ToString", new Type[] { typeof(string) }), pathSelector?.Body), select._diymemexpWithTempQuery, null, null);
|
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule,
|
||||||
|
Expression.Call(typeof(Convert).GetMethod("ToString", new Type[] { typeof(string) }), pathSelector?.Body), select._diymemexpWithTempQuery, null, null);
|
||||||
break;
|
break;
|
||||||
case DataType.MySql:
|
case DataType.MySql:
|
||||||
case DataType.OdbcMySql:
|
case DataType.OdbcMySql:
|
||||||
case DataType.CustomMySql:
|
case DataType.CustomMySql:
|
||||||
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule, pathSelector?.Body, select._diymemexpWithTempQuery, null, null);
|
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule,
|
||||||
|
Expression.Call(typeof(Convert).GetMethod("ToString", new Type[] { typeof(string) }), pathSelector?.Body), select._diymemexpWithTempQuery, null, null);
|
||||||
sql1ctePath = $"CAST({sql1ctePath} as char(2000))";
|
sql1ctePath = $"CAST({sql1ctePath} as char(2000))";
|
||||||
wct2ctePath = sql1ctePath;
|
wct2ctePath = sql1ctePath;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule, pathSelector?.Body, select._diymemexpWithTempQuery, null, null);
|
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule,
|
||||||
|
Expression.Call(typeof(Convert).GetMethod("ToString", new Type[] { typeof(string) }), pathSelector?.Body), select._diymemexpWithTempQuery, null, null);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sql1ctePath = $"{sql1ctePath} as cte_path, ";
|
sql1ctePath = $"{sql1ctePath} as cte_path, ";
|
||||||
|
@ -6337,115 +6337,3 @@
|
|||||||
</member>
|
</member>
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
`0})">
|
|
||||||
<summary>
|
|
||||||
插入数据,传入实体集合
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="source"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.InsertOrUpdate``1">
|
|
||||||
<summary>
|
|
||||||
插入或更新数据,此功能依赖数据库特性(低版本可能不支持),参考如下:<para></para>
|
|
||||||
MySql 5.6+: on duplicate key update<para></para>
|
|
||||||
PostgreSQL 9.4+: on conflict do update<para></para>
|
|
||||||
SqlServer 2008+: merge into<para></para>
|
|
||||||
Oracle 11+: merge into<para></para>
|
|
||||||
Sqlite: replace into<para></para>
|
|
||||||
达梦: merge into<para></para>
|
|
||||||
人大金仓:on conflict do update<para></para>
|
|
||||||
神通:merge into<para></para>
|
|
||||||
MsAccess:不支持<para></para>
|
|
||||||
注意区别:FreeSql.Repository 仓储也有 InsertOrUpdate 方法(不依赖数据库特性)
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Update``1">
|
|
||||||
<summary>
|
|
||||||
修改数据
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Update``1(System.Object)">
|
|
||||||
<summary>
|
|
||||||
修改数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Select``1">
|
|
||||||
<summary>
|
|
||||||
查询数据
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Select``1(System.Object)">
|
|
||||||
<summary>
|
|
||||||
查询数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Delete``1">
|
|
||||||
<summary>
|
|
||||||
删除数据
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Delete``1(System.Object)">
|
|
||||||
<summary>
|
|
||||||
删除数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
|
||||||
</summary>
|
|
||||||
<typeparam name="T1"></typeparam>
|
|
||||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Transaction(System.Action)">
|
|
||||||
<summary>
|
|
||||||
开启事务(不支持异步)<para></para>
|
|
||||||
v1.5.0 关闭了线程事务超时自动提交的机制
|
|
||||||
</summary>
|
|
||||||
<param name="handler">事务体 () => {}</param>
|
|
||||||
</member>
|
|
||||||
<member name="M:IFreeSql.Transaction(System.Data.IsolationLevel,System.Action)">
|
|
||||||
<summary>
|
|
||||||
开启事务(不支持异步)<para></para>
|
|
||||||
v1.5.0 关闭了线程事务超时自动提交的机制
|
|
||||||
</summary>
|
|
||||||
<param name="isolationLevel"></param>
|
|
||||||
<param name="handler">事务体 () => {}</param>
|
|
||||||
</member>
|
|
||||||
<member name="P:IFreeSql.Ado">
|
|
||||||
<summary>
|
|
||||||
数据库访问对象
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:IFreeSql.Aop">
|
|
||||||
<summary>
|
|
||||||
所有拦截方法都在这里
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:IFreeSql.CodeFirst">
|
|
||||||
<summary>
|
|
||||||
CodeFirst 模式开发相关方法
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:IFreeSql.DbFirst">
|
|
||||||
<summary>
|
|
||||||
DbFirst 模式开发相关方法
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:IFreeSql.GlobalFilter">
|
|
||||||
<summary>
|
|
||||||
全局过滤设置,可默认附加为 Select/Update/Delete 条件
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
</members>
|
|
||||||
</doc>
|
|
||||||
|
@ -105,7 +105,7 @@ namespace FreeSql.Xugu
|
|||||||
}
|
}
|
||||||
var value = ExpressionGetValue(callExp.Object, out var success);
|
var value = ExpressionGetValue(callExp.Object, out var success);
|
||||||
if (success) return formatSql(value, typeof(string), null, null);
|
if (success) return formatSql(value, typeof(string), null, null);
|
||||||
return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as text)" : null;
|
return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as varchar)" : null;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -373,10 +373,10 @@ namespace FreeSql.Xugu
|
|||||||
if (exp.Arguments[1].Type == typeof(bool) ||
|
if (exp.Arguments[1].Type == typeof(bool) ||
|
||||||
exp.Arguments[1].Type == typeof(StringComparison)) likeOpt = "ILIKE";
|
exp.Arguments[1].Type == typeof(StringComparison)) likeOpt = "ILIKE";
|
||||||
}
|
}
|
||||||
if (exp.Method.Name == "StartsWith") return $"({left}) {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as text) || '%')")}";
|
if (exp.Method.Name == "StartsWith") return $"({left}) {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as varchar) || '%')")}";
|
||||||
if (exp.Method.Name == "EndsWith") return $"({left}) {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || cast({args0Value} as text))")}";
|
if (exp.Method.Name == "EndsWith") return $"({left}) {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || cast({args0Value} as varchar))")}";
|
||||||
if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}";
|
if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}";
|
||||||
return $"({left}) {likeOpt} ('%' || cast({args0Value} as text) || '%')";
|
return $"({left}) {likeOpt} ('%' || cast({args0Value} as varchar) || '%')";
|
||||||
case "ToLower": return $"lower({left})";
|
case "ToLower": return $"lower({left})";
|
||||||
case "ToUpper": return $"upper({left})";
|
case "ToUpper": return $"upper({left})";
|
||||||
case "Substring":
|
case "Substring":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user