mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	- 增加 $"" lambda 解析;
This commit is contained in:
		@@ -125,13 +125,6 @@
 | 
				
			|||||||
            清空状态数据
 | 
					            清空状态数据
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
        <member name="M:FreeSql.DbSet`1.RemoveAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
 | 
					 | 
				
			||||||
            <summary>
 | 
					 | 
				
			||||||
            根据 lambda 条件删除数据
 | 
					 | 
				
			||||||
            </summary>
 | 
					 | 
				
			||||||
            <param name="predicate"></param>
 | 
					 | 
				
			||||||
            <returns></returns>
 | 
					 | 
				
			||||||
        </member>
 | 
					 | 
				
			||||||
        <member name="M:FreeSql.DbSet`1.Add(`0)">
 | 
					        <member name="M:FreeSql.DbSet`1.Add(`0)">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            添加
 | 
					            添加
 | 
				
			||||||
@@ -486,14 +479,5 @@
 | 
				
			|||||||
            <param name="that"></param>
 | 
					            <param name="that"></param>
 | 
				
			||||||
            <returns></returns>
 | 
					            <returns></returns>
 | 
				
			||||||
        </member>
 | 
					        </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>
 | 
					    </members>
 | 
				
			||||||
</doc>
 | 
					</doc>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -159,6 +159,13 @@ namespace FreeSql.Tests
 | 
				
			|||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void Test03()
 | 
					        public void Test03()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            var testStringFormat = g.sqlite.Select<Edi>().First(a => new {
 | 
				
			||||||
 | 
					                str = $"x{a.Id}_{DateTime.Now.ToString("yyyyMM")}z",
 | 
				
			||||||
 | 
					                str2 = string.Format("{0}x{0}_{1}z", a.Id, DateTime.Now.ToString("yyyyMM"))
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var sql123 = g.sqlserver.Select<Edi>()
 | 
					            var sql123 = g.sqlserver.Select<Edi>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                .WithSql(
 | 
					                .WithSql(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -716,7 +716,31 @@ namespace FreeSql.Internal
 | 
				
			|||||||
                    string other3Exp = null;
 | 
					                    string other3Exp = null;
 | 
				
			||||||
                    switch (callType.FullName)
 | 
					                    switch (callType.FullName)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        case "System.String": other3Exp = ExpressionLambdaToSqlCallString(exp3, tsc); break;
 | 
					                        case "System.String":
 | 
				
			||||||
 | 
					                            //$"{id}_{name}"
 | 
				
			||||||
 | 
					                            if (exp3.Method.Name == "Format" && exp3.Object == null && exp3.Arguments[0].NodeType == ExpressionType.Constant)
 | 
				
			||||||
 | 
					                            {
 | 
				
			||||||
 | 
					                                if (exp3.Arguments.Count == 1) return ExpressionLambdaToSql(exp3.Arguments[0], tsc);
 | 
				
			||||||
 | 
					                                var exp3Args0 = (exp3.Arguments[0] as ConstantExpression)?.Value?.ToString().Replace("{{", "{{_freesql_tMp_fLag_");
 | 
				
			||||||
 | 
					                                var exp3Args1n = exp3.Arguments.Where((a, z) => z > 0).Select(a => ExpressionLambdaToSql(a, tsc)).ToArray();
 | 
				
			||||||
 | 
					                                var exp3Args0Spt = Regex.Split(exp3Args0, @"{(\d+)}");
 | 
				
			||||||
 | 
					                                var exp3ArgsConcatType = new Type[exp3Args0Spt.Length];
 | 
				
			||||||
 | 
					                                exp3Args0Spt[0] = _common.FormatSql("{0}", exp3Args0Spt[0].Replace("{{_freesql_tMp_fLag_", "{{"));
 | 
				
			||||||
 | 
					                                exp3ArgsConcatType[0] = typeof(string);
 | 
				
			||||||
 | 
					                                for (var exp3Args0SptIndex = 1; exp3Args0SptIndex < exp3Args0Spt.Length; exp3Args0SptIndex += 2)
 | 
				
			||||||
 | 
					                                {
 | 
				
			||||||
 | 
					                                    var exp3Args1nIndex = int.Parse(exp3Args0Spt[exp3Args0SptIndex]);
 | 
				
			||||||
 | 
					                                    exp3Args0Spt[exp3Args0SptIndex] = exp3Args1n[exp3Args1nIndex];
 | 
				
			||||||
 | 
					                                    var expArgsType = exp3.Arguments[exp3Args1nIndex + 1];
 | 
				
			||||||
 | 
					                                    exp3ArgsConcatType[exp3Args0SptIndex] = (expArgsType as UnaryExpression)?.Operand.Type ?? expArgsType.Type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                    exp3Args0Spt[exp3Args0SptIndex + 1] = _common.FormatSql("{0}", exp3Args0Spt[exp3Args0SptIndex + 1].Replace("{{_freesql_tMp_fLag_", "{{"));
 | 
				
			||||||
 | 
					                                    exp3ArgsConcatType[exp3Args0SptIndex + 1] = typeof(string);
 | 
				
			||||||
 | 
					                                }
 | 
				
			||||||
 | 
					                                return _common.StringConcat(exp3Args0Spt, exp3ArgsConcatType);
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            other3Exp = ExpressionLambdaToSqlCallString(exp3, tsc); 
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
                        case "System.Math": other3Exp = ExpressionLambdaToSqlCallMath(exp3, tsc); break;
 | 
					                        case "System.Math": other3Exp = ExpressionLambdaToSqlCallMath(exp3, tsc); break;
 | 
				
			||||||
                        case "System.DateTime": other3Exp = ExpressionLambdaToSqlCallDateTime(exp3, tsc); break;
 | 
					                        case "System.DateTime": other3Exp = ExpressionLambdaToSqlCallDateTime(exp3, tsc); break;
 | 
				
			||||||
                        case "System.TimeSpan": other3Exp = ExpressionLambdaToSqlCallTimeSpan(exp3, tsc); break;
 | 
					                        case "System.TimeSpan": other3Exp = ExpressionLambdaToSqlCallTimeSpan(exp3, tsc); break;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user