0

查询连接 ProductID 上的两个表。表名为“product”和“SpecialOfferProduct”。我想要的是加入 ID 相同的 ProductID 上的表,从产品中选择名称。我这样做了,但它没有向我显示产品的名称。

 private void Button_Click_8(object sender, RoutedEventArgs e)
        {
            using (LinqContainer context = new LinqContainer())
            {
                List<Product> pro=new List<Product>() ;


                var specialOffer = (from c in context.SpecialOfferProducts
                                           join p in pro on c.ProductID equals p.ProductID
                                            select new {p.Name})
                                            .ToList();
                grid.ItemsSource = specialOffer;

            }
4

1 回答 1

0

尝试这个

  var specialOffer = (from c in context.SpecialOfferProducts
                                       join p in context.Products on c.ProductID equals p.ProductID
                                        select p.Name)
                                        .ToList();

代替

  var specialOffer = (from c in context.SpecialOfferProducts
                                       join p in pro on c.ProductID equals p.ProductID
                                        select new {p.Name})
                                        .ToList();
于 2013-05-27T10:26:30.997 回答