1

我要简化数据库。
这是它的样子:

表:

Main: Products: ID, Ref, Price, 
Translation: ID, Product_ID, Language_ID, Name
Images: ID, Product_ID, Path, Index

我是 linq 的新手,我尝试检索所有产品,它们的名称为 language_ID = 1 和索引 = 1 的图像

From p In db.Products 
Join t In db.Translate_Products On p.ID_Product Equals t.Product_ID 
Join i In db.Images On p.ID_Product Equals i.Product_ID 
Where t.Language_ID = 1 And i.Index= 0 
Select p, t, i
4

2 回答 2

2
From p In db.Products 
Join t In db.Translate_Products On p.ID_Product equals t.Product_ID into results1
from r1 in results.DefaultIfEmpty()
Join i In db.Images On p.ID_Product equals i.Product_ID 
into results2
from r2 in results2.DefaultIfEmpty()
Where results.Language_ID = 1 And i.Index= 0 
Select new
{

Productid = p.Productid,
..
..
..
}
于 2012-04-19T14:01:05.700 回答
0
From p In db.Products 
Join t In db.Translate_Products On p.ID_Product equals t.Product_ID 
into results1
from r1 in results1.DefaultIfEmpty()
Join i In db.Images On p.ID_Product equals i.Product_ID     
Where t.Language_ID == 1 And i.Index== 0 
Select new
{

Productid = p.Productid,
..
..
..
}
于 2012-04-20T09:41:51.203 回答