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(); }
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()); }
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); }
/// <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; })); }
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); }
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); }
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); }