Beispiel #1
0
        public Task <string> GetAppSecuret(long appId)
        {
            var sql = new SQLinq <ApplicationEntity>(this.SqlDialect).Where(x => x.Id == appId && x.Enable).Select(x => x.AppScret).ToSQL();

            sql.ToQuery();
            return(this.Connection.QueryFirstAsync <string>(sql.ToQuery(), sql.Parameters));
        }
Beispiel #2
0
        public Task <IEnumerable <TOut> > QueryAndSelectAsync <TOut>(Expression <Func <T, bool> > condition, Expression <Func <T, object> > selector)
        {
            var sql = new SQLinq <T>(this.SqlDialect).Where(condition).Select(selector).ToSQL();

            this.Logger.LogDebug($"SQL:{sql.ToQuery()}{Environment.NewLine}Params:{sql.Parameters}");
            return(this.Connection.QueryAsync <TOut>(sql.ToQuery(), sql.Parameters));
        }
Beispiel #3
0
        public Task <T> QueryFirstAsync(Expression <Func <T, bool> > condition)
        {
            var sql = new SQLinq <T>(this.SqlDialect).Where(condition).ToSQL();

            this.Logger.LogDebug($"SQL:{sql.ToQuery()}{Environment.NewLine}Params:{sql.Parameters}");

            return(this.Connection.QueryFirstOrDefaultAsync <T>(sql.ToQuery(), sql.Parameters));
        }
Beispiel #4
0
        public async Task <PagingList <T> > QueryByPagingAsync(Expression <Func <T, bool> > condition, Expression <Func <T, object> > orderBy, int pageIndex, int pageSize)
        {
            var sql      = new SQLinq <T>(this.SqlDialect).Where(condition).Count().ToSQL();
            var allQuery = sql.ToQuery();

            this.Logger.LogDebug($"SQL:{sql.ToQuery()}{Environment.NewLine}Params:{sql.Parameters}");
            var totalCount = await this.Connection.ExecuteScalarAsync <int>(allQuery, sql.Parameters);


            var pageSql = new SQLinq <T>(this.SqlDialect).Where(condition).OrderBy(orderBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToSQL();

            this.Logger.LogDebug($"SQL:{pageSql.ToQuery()}{Environment.NewLine}Params:{pageSql.Parameters}");
            var items = await this.Connection.QueryAsync <T>(pageSql.ToQuery(), pageSql.Parameters);

            return(new PagingList <T>(totalCount, pageIndex, pageSize, items));
        }
Beispiel #5
0
        public void DeleteSQLTest_Success()
        {
            var result = new SQLinq <TestClass>().Where(x => x.Id == 1024).ToDeleteSQL();
            var q      = result.ToQuery();
            var p      = result.Parameters;

            Assert.Equal(q, "DELETE FROM [TestClass] WHERE [Id] = @sqlinq_1");
            Assert.Equal(p["@sqlinq_1"], 1024);
        }
        public Task <List <long> > GetUserIdsAsync(long roleId)
        {
            var sql = new SQLinq <UserRoleRelation>(new MySqlDialect()).Where(x => x.RoleId == roleId).Select(x => x.UserId).ToSQL();

            return(base.Connection.QueryAsync <long>(sql.ToQuery(), sql.Parameters).ContinueWith(x => x.Result.ToList()));
        }