コード例 #1
0
        public void DictionaryPropertiesConstantWithNullPropValue()
        {
            Hashtable hashtable = new Hashtable();

            hashtable["EmployeeID"] = -1;
            hashtable["FirstName"]  = "Immo";
            hashtable["DOB"]        = new DateTime(1981, 10, 19);

            PropertyBinding[] customProps = DictionaryPropertyProvider.GetProperties(hashtable);
            hashtable["FirstName"] = null;

            Expression <object> expr = new Expression <object>();

            expr.DataContext.Constants.Add(new ConstantBinding("Constant", hashtable, customProps));
            expr.Text = "Constant.FirstName = 'Immo'";

            Assert.AreEqual(typeof(bool), expr.Resolve());
            Assert.AreEqual(null, expr.Evaluate());
        }
コード例 #2
0
        public void DictionaryPropertiesParameterNullValue()
        {
            Hashtable hashtable = new Hashtable();

            hashtable["EmployeeID"] = -1;
            hashtable["FirstName"]  = "Immo";
            hashtable["DOB"]        = new DateTime(1981, 10, 19);

            PropertyBinding[] customProps = DictionaryPropertyProvider.GetProperties(hashtable);

            Expression <object> expr = new Expression <object>();

            expr.Parameters.Add(new ParameterBinding("@Parameter", typeof(IDictionary), customProps));
            expr.Parameters["@Parameter"].Value = null;

            expr.Text = "@Parameter.FirstName = 'Immo'";

            Assert.AreEqual(typeof(bool), expr.Resolve());
            Assert.AreEqual(null, expr.Evaluate());
        }
コード例 #3
0
        private void runParameterWithCustomPropertiesButton_Click(object sender, EventArgs e)
        {
            #region Parameter with Custom Properties

            Query query = new Query();

            Dictionary <string, object> myDictionary = new Dictionary <string, object>();
            myDictionary["DateTimeProp"] = DateTime.Now;
            myDictionary["IntProp"]      = 42;
            myDictionary["StringProp"]   = Environment.UserName;

            query.Parameters.Add("@Param", typeof(Dictionary <string, object>), myDictionary, DictionaryPropertyProvider.GetProperties(myDictionary));
            query.Text = "SELECT @Param.IntProp, @Param.StringProp, @Param.DateTimeProp";
            dataGridView1.DataSource = query.ExecuteDataTable();

            #endregion
        }
コード例 #4
0
        public void DictionaryProperties()
        {
            Query query = QueryFactory.CreateQuery();

            query.Text = @"
SELECT	e.EmployeeID,
		e.FirstName,
		e.LastName
FROM	Employees e
WHERE	e.EmployeeID BETWEEN 1 AND 2
ORDER	BY 1
";

            Hashtable hashtable = new Hashtable();

            hashtable["EmployeeID"] = -1;
            hashtable["FirstName"]  = "";
            hashtable["LastName"]   = "";

            ParameterBinding    param = new ParameterBinding("@ROW", typeof(IDictionary), DictionaryPropertyProvider.GetProperties(hashtable));
            Expression <object> expr  = new Expression <object>();

            expr.DataContext = query.DataContext;
            expr.Parameters.Add(param);

            DataTable dataTable = query.ExecuteDataTable();

            foreach (DataRow row in dataTable.Rows)
            {
                Hashtable rowHashtable = new Hashtable();
                param.Value = rowHashtable;

                foreach (DataColumn col in dataTable.Columns)
                {
                    rowHashtable[col.ColumnName] = row[col];
                }

                foreach (DataColumn col in dataTable.Columns)
                {
                    expr.Text = "@ROW.[" + col.ColumnName + "]";
                    Assert.AreEqual(row[col], expr.Evaluate());
                }
            }
        }