user1037839
user1037839

Reputation:

How do that (simple?) linq query

I'm gonna simplified the db.
Here's what it looks like:

Tables:

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

I'm newbie with linq and I tried that to retrieve all products, their name with language_ID = 1 and the Image where Index = 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

Upvotes: 1

Views: 125

Answers (2)

ajay swamy
ajay swamy

Reputation: 271

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

Upvotes: 0

ajay swamy
ajay swamy

Reputation: 271

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

Upvotes: 1

Related Questions