在一個項目中,我有一個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