I am very new at Linq. I am trying to do Linq JOIN in my project but I cannot do it properly. No data comes out of the Linq statement.
Would you please give me a hint for below?
companyVM[0].brand_relations = (from cbr in db.AY_COMPANY_BRAND_RELATIONS
join c in db.AY_COMPANIES on cbr.COMPANY_ID equals c.ID
join b in db.AY_BRANDS on cbr.BRAND_ID equals b.ID
where cbr.COMPANY_ID == ID
select b).ToList();
I am very sure that some rows must come from the DB. Am I doing a syntax error?
Your first join doesn't use c
at all. This:
join c in db.AY_COMPANIES on cbr.COMPANY_ID equals ID
should almost certainly be
join c in db.AY_COMPANIES on cbr.COMPANY_ID equals c.ID
(or whatever the ID should map to within db.AY_COMPANIES
).
It's at least surprising that you don't use c
anywhere else in the query, too.
See more on this question at Stackoverflow