在我的ASP.NET核心应用程序中,我在以下查询中收到以下错误:
错误CS0119 :'products'是一种类型,在给定的上下文中无效
注意:以上错误位于以下查询的join prod in products on.....
行
LINQ查询:
using System.Linq;
var innerJoinQuery =
from category in categories
join prod in products on category.ID equals prod.ID
select new { ProductName = prod.Name, Category = category.Name };
类别:
public class category
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
public string categoryNumber { get; set; }
}
产品:
public class product
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
public string productNumber { get; set; }
}
注意:这是一个code first
应用程序,其中包含上述模型类。
答案 0 :(得分:2)
var db = new ProjNameDbContext();
var innerJoinQuery =
from category in db.categories
join prod in db.products on category.ID equals prod.CategoryID
select new { ProductName = prod.Name, Category = category.Name };