public void ConstantFoldingDoesPreserveType() { DataTable dataTable = new DataTable(); dataTable.Columns.Add("NonNullInt", typeof(int)); dataTable.Columns.Add("NullInt", typeof(int)); DataRow dataRow = dataTable.NewRow(); dataRow["NonNullInt"] = 1; dataTable.Rows.Add(dataRow); DataColumnPropertyBinding[] dataRowProperties = DataRowPropertyProvider.GetProperties(dataTable); DataContext dataContext = new DataContext(); dataContext.Constants.Add("DataRow", dataRow, dataRowProperties); Expression <object> exprWithNonNullInt = new Expression <object>(); exprWithNonNullInt.DataContext = dataContext; exprWithNonNullInt.Text = "DataRow.NonNullInt"; Assert.AreEqual(typeof(int), exprWithNonNullInt.Resolve()); Assert.AreEqual(1, exprWithNonNullInt.Evaluate()); Expression <object> exprWithNullInt = new Expression <object>(); exprWithNullInt.DataContext = dataContext; exprWithNullInt.Text = "DataRow.NullInt"; Assert.AreEqual(typeof(int), exprWithNullInt.Resolve()); Assert.AreEqual(null, exprWithNullInt.Evaluate()); }
public void DBNullAsPropertyValue() { DataTable dataTable = new DataTable(); dataTable.Columns.Add("ID1", typeof(int)); dataTable.Columns.Add("ID2", typeof(int)); DataRow dataRow = dataTable.Rows.Add(DBNull.Value, DBNull.Value); Expression <bool> expression = new Expression <bool>(); expression.Text = "row.ID1 = row.ID2"; expression.Parameters.Add("row", typeof(DataRow), dataRow, DataRowPropertyProvider.GetProperties(dataTable)); Assert.IsFalse(expression.Evaluate()); }
public void DataRowProperties() { 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 "; DataTable result = query.ExecuteDataTable(); Assert.AreEqual(2, result.Rows.Count); Expression <object> expr = new Expression <object>(); expr.DataContext = query.DataContext; ParameterBinding param = new ParameterBinding("@ROW", typeof(DataRow), DataRowPropertyProvider.GetProperties(result)); expr.Parameters.Add(param); param.Value = result.Rows[0]; expr.Text = "@ROW.EmployeeID"; Assert.AreEqual(1, expr.Evaluate()); expr.Text = "@ROW.FirstName"; Assert.AreEqual("Nancy", expr.Evaluate()); expr.Text = "@ROW.LastName"; Assert.AreEqual("Davolio", expr.Evaluate()); param.Value = result.Rows[1]; expr.Text = "@ROW.EmployeeID"; Assert.AreEqual(2, expr.Evaluate()); expr.Text = "@ROW.FirstName"; Assert.AreEqual("Andrew", expr.Evaluate()); expr.Text = "@ROW.LastName"; Assert.AreEqual("Fuller", expr.Evaluate()); }