Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq 查询未显示正确的结果_Linq_Linq To Sql_Linq To Entities - Fatal编程技术网

Linq 查询未显示正确的结果

Linq 查询未显示正确的结果,linq,linq-to-sql,linq-to-entities,Linq,Linq To Sql,Linq To Entities,查询将ProductID上的两个表连接起来。表名为“product”和“SpecialOfferProduct”。我想要的是连接ProductID上的表,其中Id与select Name from Product相同。我是这样做的,但它没有告诉我产品的名称 private void Button_Click_8(object sender, RoutedEventArgs e) { using (LinqContainer context = new L

查询将ProductID上的两个表连接起来。表名为“product”和“SpecialOfferProduct”。我想要的是连接ProductID上的表,其中Id与select Name from Product相同。我是这样做的,但它没有告诉我产品的名称

 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;

            }
private void按钮\u单击\u 8(对象发送者,路由目标)
{
使用(LinqContainer context=new LinqContainer())
{
List pro=新列表();
var specialOffer=(来自context.SpecialOfferProducts中的c
在c.ProductID等于p.ProductID的pro中加入p
选择新的{p.Name})
.ToList();
grid.ItemsSource=specialOffer;
}
试试这个

  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();

您确定list specialOffer为空吗?(只是为了检查查询或数据网格中的错误)在上下文中加入p。c.ProductID上的产品等于p.ProductID这解决了我的问题“无论如何谢谢”