在一个项目中,我有一个LINQ to SQL类,它是OrderingSystem.dbml。我有以下代码,并且在select语句中,我只想从每个表中检索一些行(产品 - 类别)。但是,当然,我现在的回归声明是不正确的。什么是正确的返回语句使用?在此先感谢LINQ to SQL返回语句
OrderingSystemDataContext database = new OrderingSystemDataContext();
public List<Product> GetProductsByCategoryID(int CategoryID)
{
var result = from p in database.Products
join c in database.Categories
on p.CategoryID equals c.CategoryID
where p.CategoryID == CategoryID
select new { p.ProductName, p.ProductPrice, p.ProductDescription, c.CategoryName };
//This is not working
return result.ToList();
}
你是不是指什么意思? –
@ DanielA.White从Visual Studio的确切错误是“不能隐式转换类型'System.Collections.Generic.List'到'System.Collections.Generic.List '” –
您是否甚至需要一个where子句给你加入这些相同的列?同样在where子句中,第二个CategoryID看起来不明确。 – radarbob