プロジェクトでは、LINQ to SQLクラスがOrderingSystem.dbmlです。私は次のコードを持っているとselect文では、各テーブル(製品 - カテゴリ)からいくつかの行のみを取得したい。しかし、もちろん私が今持っているリターンステートメントは正しくありません。正しいreturn文は何ですか?選択新しいオン事前に感謝LINQ to SQL return文
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句では、2番目のCategoryIDがあいまいに見えます。 – radarbob