Reputation: 1565
I'm trying to do a join/ association in entity framework using linq.
I have the following two tables:
id name country_code(same as iso3) etc...
id name iso3
I have tried the following but i'm getting stuck at where to associate the objects with each other:
List<Institution> ins = _context.Institution
.Include(o => o.country)
thanks
Upvotes: 0
Views: 311
Reputation: 2128
var ins =
_context.Institution
.Join(_context.Country,
inst => inst.country_code,
ctry => ctry.iso3,
(inst, ctry) => new { Institution = inst, Country = ctry }).ToList();
Upvotes: 1
Reputation: 1565
Thanks for your help, I've added an extra column to the institution table called country_id, i'm sure there's probably a way I could have mapped the country_code of country to the institution entity, but I took the quick and easy way out.
Thanks again
Upvotes: 0
Reputation: 4344
if iso3 and country_code is not bound with a foreign constraint you should use .Join for lambda expression. Check the link here
Upvotes: 2