0

我已经研究了一段时间,所以如果我在某个地方错过了一个主题,请指出我正确的方向并接受我的道歉。

我正在对传入的 DataTable 执行 LINQ 查询,并根据完成的过滤设置新列。传入的信息是包含以下列的单行:CompanyName、CustomerID、LastName、FirstName、ContactTitle。

我的问题是,我是否对信息进行了过度过滤,以至于它不会向 DGV 返回任何内容,还是我做错了什么?

我要做的是根据从 DataTable 传入的信息查询另一个表。这是我的查询:

            var query = (from id in IncomingOrderDetails.AsEnumerable()
                    from o in db.Orders
                    from c in db.Customers
                    from r in db.Regions
                    where (id.Field<int>("OrderID") == o.OrderID)
                    where (o.CustomerID == c.CustomerID)
                    where (c.Region == r.RegionDescription)
                    select new
                    {
                        CustomerID = c.CustomerID,
                        CompanyName = c.CompanyName,
                        ContactName = c.ContactName,
                        RegionDescription = r.RegionDescription,
                        Country = c.Country,
                        Phone = c.Phone
                    }).ToList();

        custInfoDGV.DataSource = query;
4

1 回答 1

0

这一行:

 where (c.Region == r.RegionDescription)

...看起来很可疑。如果c.Region = r.RegionDescription,你为什么需要引入r呢?您使用它的所有目的都是检索 RegionDescription。

I don't know your tables, but joining two fields that don't match would certainly produce 0 records returned. :)

于 2012-12-06T18:20:12.183 回答