Beispiel #1
0
        /// <summary>
        /// 动态生成LINQ查询,并将数据填入DataGridView控件中.
        /// </summary>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            // 从控件中获取条件.
            var c = ConditionBuilder1.GetCondition <Order>();

            // 筛选掉不符合条件的所有Orders.
            // 注意,由于延迟执行,实际上尚未执行查询.
            var filteredQuery = db.Orders.Where(c);

            // 我们现在可以执行其他任何操作(例如Order By或者Select)在filteredQuery中.
            var query = from row in filteredQuery
                        orderby row.OrderDate, row.OrderID
            select row;

            // 执行查询,并将结果显示在DataGridView控件中.
            dgResult.DataSource = query;
        }
        /// <summary>
        /// Dynamically generate LINQ query and put it into DataGridView Control
        /// </summary>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            // Get the Condition out of the control
            var c = ConditionBuilder1.GetCondition <Order>();

            // Filter out all Orders that don't match the Condition
            // Note that the query does not actually get executed yet to due to deferred execution
            var filteredQuery = db.Orders.Where(c);

            // We can now perform any other operations (such as Order By or Select) on filteredQuery
            var query = from row in filteredQuery
                        orderby row.OrderDate, row.OrderID
            select row;

            // Executes the query and displays the results in DataGridView1
            dgResult.DataSource = query;
        }