2012-04-19 8 views
1

私はdbを単純化するつもりです。どうすればいいのですか(簡単?)linqクエリ

テーブル::

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

あなたは_ "どのように私は答えを受け入れるん" _尋ねるべき! ** 10点中0点**印象深い! – gdoron

+2

13質問、0受け入れる、あなたはStackExchangeの仕組みを読むことを検討したいかもしれない –

+0

どういう意味ですか? – blop

答えて

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, 
.. 
.. 
.. 
} 
+0

実際に私はそれが仕事を得ることができません...ビジュアルスタジオdoes notは私に2番目の行に "を"持っています...どちらも動作しない方法を理解してください... – blop

+0

into LINQ .. Valid p.ID_Productとt.Product_IDが同じタイプの場合.. –

+0

ビジュアルスタジオは "end of instruction excited"と書いてあります(それはbleuで下線が引かれています) – blop

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, 
.. 
.. 
.. 
} 
+0

しかし、まだ動作していません...ちょうど書き込みからpのdb.Productsに参加するdb.Translate_Productsでp.ID_Productsでt.Product_IDに等しい結果1は私にエラーを与えます...それはVBですか? – blop

+0

それはC#のコードです。私は同じクエリを使用していますが、異なるテーブルとそれは私のために非常にうまく動作します..あなたのケースバディを知らない... –

+0

私はVBを使用しています...それは問題ですか?私はVBでのlinqとC#は同じだと思った.... – blop

関連する問題