mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 17:20:49 +08:00 
			
		
		
		
	- 优化 ISelect.Count() 之前使用了 OrderBy 会产生的 SQL 语法问题;
This commit is contained in:
		@@ -762,8 +762,9 @@ namespace FreeSql.Internal
 | 
			
		||||
                                    else if (fsqlType != null)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        var call3Exp = exp3tmp as MethodCallExpression;
 | 
			
		||||
                                        var method = fsqlType.GetMethod(call3Exp.Method.Name, call3Exp.Arguments.Select(a => a.Type).ToArray());
 | 
			
		||||
                                        if (call3Exp.Method.ContainsGenericParameters) method.MakeGenericMethod(call3Exp.Method.GetGenericArguments());
 | 
			
		||||
                                        var method = call3Exp.Method;
 | 
			
		||||
                                        //var method = fsqlType.GetMethod(call3Exp.Method.Name, call3Exp.Arguments.Select(a => a.Type).ToArray());
 | 
			
		||||
                                        //if (call3Exp.Method.ContainsGenericParameters) method.MakeGenericMethod(call3Exp.Method.GetGenericArguments());
 | 
			
		||||
                                        var parms = method.GetParameters();
 | 
			
		||||
                                        var args = new object[call3Exp.Arguments.Count];
 | 
			
		||||
                                        for (var a = 0; a < args.Length; a++)
 | 
			
		||||
 
 | 
			
		||||
@@ -158,7 +158,19 @@ namespace FreeSql.Internal.CommonProvider
 | 
			
		||||
            return this.ToList<int>("1 as1").Sum() > 0; //这里的 Sum 为了分表查询
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public long Count() => this.ToList<int>("count(1) as1").Sum(); //这里的 Sum 为了分表查询
 | 
			
		||||
        public long Count()
 | 
			
		||||
        {
 | 
			
		||||
            var tmpOrderBy = _orderby;
 | 
			
		||||
            _orderby = null; //解决 select count(1) from t order by id 这样的 SQL 错误
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return this.ToList<int>("count(1) as1").Sum(); //这里的 Sum 为了分表查询
 | 
			
		||||
            }
 | 
			
		||||
            finally
 | 
			
		||||
            {
 | 
			
		||||
                _orderby = tmpOrderBy;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public TSelect Count(out long count)
 | 
			
		||||
        {
 | 
			
		||||
@@ -1111,7 +1123,19 @@ namespace FreeSql.Internal.CommonProvider
 | 
			
		||||
            return (await this.ToListAsync<int>("1 as1")).Sum() > 0; //这里的 Sum 为了分表查询
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        async public Task<long> CountAsync() => (await this.ToListAsync<int>("count(1) as1")).Sum(); //这里的 Sum 为了分表查询
 | 
			
		||||
        async public Task<long> CountAsync()
 | 
			
		||||
        {
 | 
			
		||||
            var tmpOrderBy = _orderby;
 | 
			
		||||
            _orderby = null;
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return (await this.ToListAsync<int>("count(1) as1")).Sum(); //这里的 Sum 为了分表查询
 | 
			
		||||
            }
 | 
			
		||||
            finally
 | 
			
		||||
            {
 | 
			
		||||
                _orderby = tmpOrderBy;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        async public Task<DataTable> ToDataTableAsync(string field = null)
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user