Linq 查询未显示正确的结果
查询将ProductID上的两个表连接起来。表名为“product”和“SpecialOfferProduct”。我想要的是连接ProductID上的表,其中Id与select Name from Product相同。我是这样做的,但它没有告诉我产品的名称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
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这解决了我的问题“无论如何谢谢”