In my ASP.NET Core app, I'm getting the following error on the following query:
Error CS0119 : 'products' is a type, which is not valid in the given context
NOTE: The above error is on the line join prod in products on.....
of the following query
LINQ Query :
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 };
category :
public class category
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
public string categoryNumber { get; set; }
}
product :
public class product
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
public string productNumber { get; set; }
}
NOTE : This is a code first
application that has the above model classes among others.
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 };
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.