C# - LINQ - 在另一个 LINQ 查询的 WHERE 子句中使用列数据

http://img3.mukewang.com/60bae6000001b23611200903.jpg

所以我执行这个查询:


            var query2 = from o in db.Orders

                     join od in db.Order_Details on o.OrderID equals od.OrderID

                     group new { o, od } by o.ShipCountry into oByCountry

                     orderby oByCountry.Sum(ood => ood.od.UnitPrice * ood.od.Quantity) descending

                     select new

                     {

                         Country = oByCountry.Key,

                         Total = oByCountry.Sum(ood => ood.od.UnitPrice * ood.od.Quantity)

                     };

我将结果放在 WPF 中的数据网格中。


GridOverview.ItemsSource = query2;

我要做的下一件事是,当我在一行中按下 GridOverview 时,我想显示居住在所选行所在国家/地区的所有客户以及每个客户的已售商品总价。所以我在 var selectedRow 中定义了所选项目。


var selectedRow = GridOverview.SelectedItem;


            var query = from c in db.Customers

                    join o in db.Orders on c.CustomerID equals o.CustomerID

                    join od in db.Order_Details on o.OrderID equals od.OrderID

                    **where c.Country == selectedRow.**

                    group new {c, o, od} by c.CompanyName into cByName

                    orderby cByName.Sum(ood => ood.od.UnitPrice * ood.od.Quantity) descending

                    select new

                    {

                        cByName.Key,

                        Total = cByName.Sum(ood => ood.od.UnitPrice * ood.od.Quantity)

                    };

现在我的问题是:如何在 where 子句中将 selectedRow 的 Country 与 C.Country 进行比较?selectedRow.Country 不起作用,但这可能不是它的工作原理。



米脂
浏览 191回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP