GetQueryText() public method

public GetQueryText ( Expression expression ) : string
expression System.Linq.Expressions.Expression
return string
コード例 #1
0
ファイル: SQLQueryProvider.cs プロジェクト: seasky100/Gb28059
            public void SelectWithBooleanTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => asset.Expired;
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext + ".");

                Assert.IsTrue(querytext == "expired = '1'", "The query text was incorrect.");
            }
コード例 #2
0
ファイル: SQLQueryProvider.cs プロジェクト: seasky100/Gb28059
            public void SelectWithAndOperatorTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => asset.AdminId == "1234" && asset.Username == "abcd";
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "adminid = '1234' and username = '******'", "The query text was incorrect.");
            }
コード例 #3
0
ファイル: SQLQueryProvider.cs プロジェクト: seasky100/Gb28059
            public void SelectWithNotEqualMemberVariableOperatorTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                var myObj = new { Name = "xyz" };
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => asset.Username != myObj.Name;
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "username != '" + myObj.Name + "'", "The query text was incorrect.");
            }
コード例 #4
0
ファイル: SQLQueryProvider.cs プロジェクト: seasky100/Gb28059
            public void SelectWithNotCombinedWithAndOperatorTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                DateTime         checkDate     = DateTime.Now;
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => !asset.Expired && asset.Inserted >= checkDate;
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext + ".");

                Assert.IsTrue(querytext == "not (expired = '1') and inserted >= '" + checkDate.ToString("o") + "'", "The query text was incorrect.");
            }
コード例 #5
0
ファイル: SQLQueryProvider.cs プロジェクト: seasky100/Gb28059
            public void SelectWithLocallyScopedVariableOperatorTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                string           username      = "******";
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => asset.Username == username;
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "username = '******'", "The query text was incorrect.");
            }
コード例 #6
0
ファイル: SQLQueryProvider.cs プロジェクト: seasky100/Gb28059
            public void SimpleSelectOnDateTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                DateTime         checkDate     = DateTime.Now;
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => asset.Inserted >= checkDate;
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "inserted >= '" + checkDate.ToString("o") + "'", "The query text was incorrect.");
            }
コード例 #7
0
ファイル: SQLQueryProvider.cs プロジェクト: seasky100/Gb28059
            public void SimpleSelectOnIdTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                Guid             id            = Guid.NewGuid();
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => asset.Id == id;
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "id = '" + id + "'", "The query text was incorrect.");
            }
コード例 #8
0
ファイル: SQLQueryProvider.cs プロジェクト: seasky100/Gb28059
            public void SelectWithMemberVariableCombinedWithAndClauseOperatorTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                var      myObj     = new { Name = "xyz" };
                DateTime checkDate = DateTime.Now;
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => asset.Username == myObj.Name && !asset.Expired && asset.Inserted >= checkDate;
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "username = '******' and not (expired = '1') and inserted >= '" + checkDate.ToString("o") + "'", "The query text was incorrect.");
            }
コード例 #9
0
ファイル: SQLQueryProvider.cs プロジェクト: seasky100/Gb28059
            public void OrderedSelectTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider     queryProvider = new SQLQueryProvider(null, null, null, null);
                Query <MockSIPAsset> assetList     = new Query <MockSIPAsset>(queryProvider);

                DateTime checkDate   = DateTime.Now;
                var      dummyResult = from asset in assetList orderby asset.Inserted select asset;
                string   querytext   = queryProvider.GetQueryText(dummyResult.Expression);

                Console.WriteLine("Query: " + querytext);

                //Assert.IsTrue(querytext == "username = '******' and not (expired = '1') and inserted >= '" + checkDate.ToString("o") + "'", "The query text was incorrect.");
            }
コード例 #10
0
        public override void Delete(Expression <Func <T, bool> > where)
        {
            try
            {
                SQLQueryProvider sqlQueryProvider = new SQLQueryProvider(m_dbProviderFactory, m_dbConnectionStr, m_objectMapper.TableName, m_objectMapper.SetValue);
                string           whereStr         = sqlQueryProvider.GetQueryText(where);

                using (IDbConnection connection = m_dbProviderFactory.CreateConnection())
                {
                    connection.ConnectionString = m_dbConnectionStr;
                    connection.Open();

                    IDbCommand deleteCommand = connection.CreateCommand();
                    deleteCommand.CommandText = "delete from " + m_objectMapper.TableName + " where " + whereStr;
                    deleteCommand.ExecuteNonQuery();
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception SQLAssetPersistor Delete (for " + typeof(T).Name + "). " + excp.Message);
                throw;
            }
        }
コード例 #11
0
            public void SelectWithMemberVariableCombinedWithAndClauseOperatorTest() {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                var myObj = new { Name = "xyz" };
                DateTime checkDate = DateTime.Now;
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.Username == myObj.Name && !asset.Expired && asset.Inserted >= checkDate;
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "username = '******' and not (expired = '1') and inserted >= '" + checkDate.ToString("o") + "'", "The query text was incorrect.");
            }
コード例 #12
0
            public void OrderedSelectTest() {

                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                Query<MockSIPAsset> assetList = new Query<MockSIPAsset>(queryProvider);

                DateTime checkDate = DateTime.Now;
                var dummyResult = from asset in assetList orderby asset.Inserted select asset;
                string querytext = queryProvider.GetQueryText(dummyResult.Expression);
                Console.WriteLine("Query: " + querytext);

                //Assert.IsTrue(querytext == "username = '******' and not (expired = '1') and inserted >= '" + checkDate.ToString("o") + "'", "The query text was incorrect.");
            }
コード例 #13
0
            public void SelectWithNotCombinedWithAndOperatorTest() {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                DateTime checkDate = DateTime.Now;
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => !asset.Expired && asset.Inserted >= checkDate;
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext + ".");

                Assert.IsTrue(querytext == "not (expired = '1') and inserted >= '" + checkDate.ToString("o") + "'", "The query text was incorrect.");
            }
コード例 #14
0
            public void SelectWithNotEqualMemberVariableOperatorTest() {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                var myObj = new { Name = "xyz" };
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.Username != myObj.Name;
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "username != '" + myObj.Name + "'", "The query text was incorrect.");
            }
コード例 #15
0
            public void SelectWithBooleanTest() {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.Expired;
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext + ".");

                Assert.IsTrue(querytext == "expired = '1'", "The query text was incorrect.");
            }
コード例 #16
0
            public void SelectWithLocallyScopedVariableOperatorTest() {

                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                string username = "******";
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.Username == username;
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "username = '******'", "The query text was incorrect.");
            }
コード例 #17
0
            public void SelectWithAndOperatorTest() {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.AdminId == "1234" && asset.Username == "abcd";
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "adminid = '1234' and username = '******'", "The query text was incorrect.");
            }
コード例 #18
0
            public void SimpleSelectOnDateTest() {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                DateTime checkDate = DateTime.Now;
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.Inserted >= checkDate;
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "inserted >= '" + checkDate.ToString("o") + "'", "The query text was incorrect.");
            }
コード例 #19
0
            public void SimpleSelectOnIdTest() {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SQLQueryProvider queryProvider = new SQLQueryProvider(null, null, null, null);
                Guid id = Guid.NewGuid();
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.Id == id;
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "id = '" + id + "'", "The query text was incorrect.");
            }