SELECT P.ProductId, P.ProductCategoryId, P.ParentProductCategoryId,
P.ProductName, PC.Name AS Category, P.Price, P.ProductYear
FROM dbo.ProductCategory AS PC
INNER JOIN
(SELECT dbo.ProductCategory.ParentProductCategoryId,
dbo.ProductCategory.ProductCategoryId,
dbo.ProductCategory.Name AS CategoryName,
dbo.Product.ProductId,
dbo.Product.Price,
dbo.Product.Name AS ProductName,
dbo.Product.ProductYear
FROM dbo.Product
INNER JOIN dbo.ProductCategory
ON dbo.ProductCategory.ProductCategoryId = dbo.Product.ProductCategoryId
) AS P
ON PC.ProductCategoryId = P.ParentProductCategoryId
1
A
答えて
1
あなたが見れば私はあなたのデータベースのレイアウトについてはかなりよく分からないが、LINQ文は次のようになります...
YourDataContext db = new YourDataContext();
var query =
from p in db.Products
join pc in db.ProductCategories on p.ProductCategoryId equals pc.ProductCategoryId
select new
{
p.ProductId,
p.ProductCategoryId,
p.ParentProductCategoryId,
p.ProductName,
Category = pc.Name,
p.Price,
p.ProductYear
}
+0
ProductCategoriesの親を子供に、次にProductにリンクしていることに注意してください。 – Benjol
+0
ああ、ある人が投稿を編集してコードブロックを使用したようです。アプリケーション。 –
はあなたがここに欲しい結果の例を含む価値があるかもしれません... – Benjol