Ejemplo n.º 1
0
 public void Test1()
 {
     string userName = null;
     var    sqlinq   = new SQLinq <UserEntity>(new MySqlDialect());
     var    ss       = sqlinq.Where(x => x.UserName.StartsWith(userName) || x.RealName.StartsWith(userName) && x.Enable == true);
     var    result   = ss.ToSQL();
 }
Ejemplo n.º 2
0
        private async Task <List <ApplicationCallbackConfig> > GetApplicationCallbackConfigsAsync(long id)
        {
            var appCallbackConfigSql = new SQLinq <ApplicationCallbackConfig>(base.SqlDialect);

            appCallbackConfigSql.Where(x => x.AppId == id);
            var sqlResult          = appCallbackConfigSql.ToSQL();
            var sql                = sqlResult.ToQuery();
            var appCallbackConfigs = await this.Connection.QueryAsync <ApplicationCallbackConfig>(sql, sqlResult.Parameters);

            return(appCallbackConfigs.ToList());
        }
Ejemplo n.º 3
0
        public void HasFlagTest_Success()
        {
            var sql = new SQLinq <FlagTestEntity>(new MySqlDialect());

            sql.Where(x => x.MyType.HasFlag(FType.A));
            //sql.Where(x => (x.TestB && true) == true);
            var sqlResult = sql.ToSQL();
            var query     = sqlResult.ToQuery();

            Assert.Equal("SELECT * FROM `FlagTestEntity` WHERE (`MyType` & @sqlinq_1) = @sqlinq_1", query);
            Assert.Equal(sqlResult.Parameters["@sqlinq_1"], FType.A);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Return an entity that match the criteria
 /// </summary>
 /// <param name="select"></param>
 /// <param name="predicate"></param>
 /// <returns></returns>
 public virtual T FirstOrDefault(Expression <Func <T, bool> > predicate)
 {
     return(Using(connection =>
     {
         var query = new SQLinq <T>();
         if (predicate != null)
         {
             query = query.Where(predicate);
         }
         var result = connection.Query(query).FirstOrDefault();
         return result;
     }));
 }
Ejemplo n.º 5
0
        public async Task <ApplicationEntity> GetAppInfoEntityAsync(long id)
        {
            var app = await base.QueryFirstAsync(x => x.Id == id);

            var sqlGenerator = new SQLinq <UserEntity>(base.SqlDialect);

            sqlGenerator.Where(x => x.Id == app.AppUserId);
            var sqlResult = sqlGenerator.ToSQL();
            var sql       = sqlResult.ToQuery();

            var userEntity = await this.Connection.QueryFirstAsync <UserEntity>(sql, sqlResult.Parameters);

            app.Account = userEntity;
            return(app);
        }
Ejemplo n.º 6
0
        public async Task <ApplicationEntity> GetAppInfoEntityAsync(Expression <Func <ApplicationEntity, bool> > condition)
        {
            var app = await base.QueryFirstAsync(condition);

            var sqlGenerator = new SQLinq <UserEntity>(base.SqlDialect);

            sqlGenerator.Where(x => x.Id == app.AppUserId);
            var sqlResult  = sqlGenerator.ToSQL();
            var sql        = sqlResult.ToQuery();
            var userEntity = await this.Connection.QueryFirstAsync <UserEntity>(sql, sqlResult.Parameters);

            await this.FillCallbackConfigs(app);

            app.Account = userEntity;
            return(app);
        }
Ejemplo n.º 7
0
        public async Task ChangeAppSecuretAsync(ApplicationEntity entity)
        {
            var sqlGenerator = new SQLinq <UserEntity>(base.SqlDialect);

            sqlGenerator.Where(x => x.Id == entity.AppUserId);
            var sqlResult = sqlGenerator.ToSQL();
            var sql       = sqlResult.ToQuery();

            var updateSqlGenerator = new SQLinqUpdate <UserEntity>(base.SqlDialect);

            updateSqlGenerator.Where(x => x.Id == entity.AppUserId);
            updateSqlGenerator.UpdateSet(() => new UserEntity {
                Password = entity.Account.Password, Salt = entity.Account.Salt
            });
            var updateSqlResult = updateSqlGenerator.ToSQL();
            var updateSql       = updateSqlResult.ToQuery();

            await this.Connection.ExecuteAsync(updateSql, updateSqlResult.Parameters);
        }