Inheritance: QueryProvider
            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.");
            }
            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.");
            }
            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.");
            }
            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.");
            }
            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.");
            }
            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.");
            }
            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.");
            }
            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.");
            }
            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.");
            }
Exemple #10
0
        public override List <T> Get(Expression <Func <T, bool> > whereClause, string orderByField, int offset, int count)
        {
            try
            {
                SQLQueryProvider sqlQueryProvider = new SQLQueryProvider(m_dbProviderFactory, m_dbConnectionStr, m_objectMapper.TableName, m_objectMapper.SetValue);
                Query <T>        assetList        = new Query <T>(sqlQueryProvider);
                //IQueryable<T> getList = from asset in assetList.Where(whereClause) orderby orderByField select asset;
                IQueryable <T> getList = null;
                if (whereClause != null)
                {
                    getList = from asset in assetList.Where(whereClause) select asset;
                }
                else
                {
                    getList = from asset in assetList select asset;
                }

                if (!orderByField.IsNullOrBlank())
                {
                    sqlQueryProvider.OrderBy = orderByField;
                }

                if (offset != 0)
                {
                    sqlQueryProvider.Offset = offset;
                }

                if (count != Int32.MaxValue)
                {
                    sqlQueryProvider.Count = count;
                }

                return(getList.ToList() ?? new List <T>());
            }
            catch (Exception excp)
            {
                string whereClauseStr = (whereClause != null) ? whereClause.ToString() + ". " : null;
                logger.Error("Exception SQLAssetPersistor Get (list) (for " + typeof(T).Name + "). " + whereClauseStr + excp.Message);
                throw;
            }
        }
Exemple #11
0
 public override int Count(Expression <Func <T, bool> > whereClause)
 {
     try
     {
         SQLQueryProvider sqlQueryProvider = new SQLQueryProvider(m_dbProviderFactory, m_dbConnectionStr, m_objectMapper.TableName, m_objectMapper.SetValue);
         Query <T>        assets           = new Query <T>(sqlQueryProvider);
         if (whereClause != null)
         {
             return(assets.Where(whereClause).Count());
         }
         else
         {
             return(assets.Count());
         }
     }
     catch (Exception excp)
     {
         logger.Error("Exception SQLAssetPersistor Count (for " + typeof(T).Name + "). " + excp.Message);
         throw;
     }
 }
Exemple #12
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;
            }
        }
Exemple #13
0
 public override T Get(Expression <Func <T, bool> > whereClause)
 {
     try
     {
         SQLQueryProvider sqlQueryProvider = new SQLQueryProvider(m_dbProviderFactory, m_dbConnectionStr, m_objectMapper.TableName, m_objectMapper.SetValue);
         Query <T>        assets           = new Query <T>(sqlQueryProvider);
         IQueryable <T>   getList          = null;
         if (whereClause != null)
         {
             getList = from asset in assets.Where(whereClause) select asset;
         }
         else
         {
             getList = from asset in assets select asset;
         }
         return(getList.FirstOrDefault());
     }
     catch (Exception excp)
     {
         string whereClauseStr = (whereClause != null) ? whereClause.ToString() + ". " : null;
         logger.Error("Exception SQLAssetPersistor Get (where) (for " + typeof(T).Name + "). " + whereClauseStr + excp);
         throw;
     }
 }
            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.");
            }
            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.");
            }
            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.");
            }
            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.");
            }
            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.");
            }
            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.");
            }
            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.");
            }
            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.");
            }
            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.");
            }