コード例 #1
0
        public void SQLinqTable_NameOverride_003()
        {
            var query  = new SQLinq <SQLinqTable_NameOverride_003_Class>("[DatabaseName].[NewTableName]");
            var result = (SQLinqSelectResult)query.ToSQL();

            Assert.AreEqual("[DatabaseName].[NewTableName]", result.Table);
        }
コード例 #2
0
        public void SQLinqTable_002()
        {
            var query  = new SQLinq <SQLinqTable_002_Class>();
            var result = (SQLinqSelectResult)query.ToSQL();

            Assert.AreEqual("[TableName]", result.Table);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: 1095776316/CoreLearn
        static void Main(string[] args)
        {
            int[]        vs     = new int[] { 1, 3, 4 };
            List <Apple> apples = new List <Apple>()
            {
                new Apple()
                {
                    Id = 1, Name = "苹果1", Price = 20, Province = "shanghai", Weight = 300
                },
                new Apple()
                {
                    Id = 2, Name = "苹果2", Price = 20, Province = "shanghai", Weight = 300
                },
                new Apple()
                {
                    Id = 3, Name = "苹果3", Price = 20, Province = "shanghai", Weight = 300
                },
                new Apple()
                {
                    Id = 4, Name = "苹果4", Price = 20, Province = "shanghai", Weight = 300
                },
                new Apple()
                {
                    Id = 5, Name = "苹果5", Price = 20, Province = "shanghai", Weight = 300
                }
            };
            var ids = apples.Select(x => x.Id).ToList();

            var s = new SQLinq <Apple>().Where(p => (p.Id == 1 || p.Id == 2) && p.Name == ("苹果") && vs.Contains(p.Id));
            var d = s.ToSQL();
            var b = d.Where;

            Console.WriteLine(b);
            Console.ReadKey();
        }
コード例 #4
0
        public static IEnumerable <T> Query <T>(this IDbConnection dbconnection, SQLinq <T> query,
                                                IDbTransaction transaction = null, bool buffered = true, int?commandTimeout = null, CommandType?commandType = null)
            where T : new()
        {
            var result = query.ToSQL();

            var sql        = result.ToQuery();
            var parameters = new DictionaryParameterObject(result.Parameters);

            return(DapperDotNet.SqlMapper.Query <T>(dbconnection, sql, parameters, transaction, buffered, commandTimeout, commandType));
        }
コード例 #5
0
ファイル: SQLinqColumnTest.cs プロジェクト: daywrite/SQLinq
        public void UseWithSQLinqSubQuery_001()
        {
            var query = new SQLinq<MyTable>();

            var result = query.ToSQL();
            var actual = result.ToQuery();

            var expected = "SELECT [Identifier] AS [ID], [FullName] AS [Name] FROM (SELECT [Identifier], [FullName] FROM [tblSomeTable]) AS [MyTable]";

            Assert.AreEqual(expected, actual);
        }
コード例 #6
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());
        }
コード例 #7
0
        public void UseWithSQLinqSubQuery_001()
        {
            var query = new SQLinq <MyTable>();

            var result = query.ToSQL();
            var actual = result.ToQuery();

            var expected = "SELECT [Identifier] AS [ID], [FullName] AS [Name] FROM (SELECT [Identifier], [FullName] FROM [tblSomeTable]) AS [MyTable]";

            Assert.AreEqual(expected, actual);
        }
コード例 #8
0
ファイル: SQLinqColumnTest.cs プロジェクト: daywrite/SQLinq
        public void UseWithSQLinqSubQuery_Oracle_001()
        {
            var dialect = new OracleDialect();
            var query = new SQLinq<MyTable>(dialect);

            var result = query.ToSQL();
            var actual = result.ToQuery();

            var expected = "SELECT Identifier AS ID, FullName AS Name FROM (SELECT [Identifier], [FullName] FROM [tblSomeTable]) AS MyTable";

            Assert.AreEqual(expected, actual);
        }
コード例 #9
0
ファイル: BitCalTest.cs プロジェクト: zqlovejyc/SQLinq
        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);
        }
コード例 #10
0
        public void UseWithSQLinqSubQuery_Oracle_001()
        {
            var dialect = new OracleDialect();
            var query   = new SQLinq <MyTable>(dialect);

            var result = query.ToSQL();
            var actual = result.ToQuery();

            var expected = "SELECT Identifier AS ID, FullName AS Name FROM (SELECT [Identifier], [FullName] FROM [tblSomeTable]) AS MyTable";

            Assert.AreEqual(expected, actual);
        }
コード例 #11
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);
        }
コード例 #12
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);
        }
コード例 #13
0
        public static int Count <T>(this SQLinq <T> query, IDbConnection connection)
        {
            var queryResult = query.ToSQL();

            queryResult.Select = new[] { "COUNT(*)" };

            var sqlParameters = queryResult.Parameters;

            var sqlCode = queryResult.ToQuery();

            var cmd = new SqlCommand(sqlCode, (SqlConnection)connection);

            foreach (var p in sqlParameters)
            {
                cmd.Parameters.AddWithValue(p.Key, p.Value);
            }

            return((int)cmd.ExecuteScalar());
        }
コード例 #14
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);
        }
コード例 #15
0
 public void SQLinqTable_NameOverride_004()
 {
     var query = new SQLinq<SQLinqTable_NameOverride_004_Class>("[DatabaseName].[NewTableName]");
     var result = (SQLinqSelectResult)query.ToSQL();
     Assert.AreEqual("[DatabaseName].[NewTableName]", result.Table);
 }
コード例 #16
0
 public void SQLinqTable_003()
 {
     var query = new SQLinq<SQLinqTable_003_Class>();
     var result = (SQLinqSelectResult)query.ToSQL();
     Assert.AreEqual("[DatabaseName].[TableName]", result.Table);
 }