Lucas_Santos
Lucas_Santos

Reputation: 4740

How can I do a JOIN with Entity Framework

How can I do a Join with another Entity ?

I have this one,

IEnumerable<EntityNetimoveis.San_Imovel> im = db.San_Imovel.Where(a => a.Credenciada_Id.Equals(10));

I want a JOIN with San_Imovel_Caracteristica. Primary Key and Foreign Key called Imovel_Id

I try this one

IEnumerable<EntityNetimoveis.San_Imovel> im = db.San_Imovel.Join.(IEnumerable<EntityNetimoveis.San_Imovel_Caracteristica>, i => imovel_id, a => imovel_Id).Where(a => a.Credenciada_Id.Equals(10));

but this is a wrong code. Has syntax error.

Upvotes: 0

Views: 3419

Answers (3)

Thiago Custodio
Thiago Custodio

Reputation: 18387

var query = from EntityNetimoveis.San_Imovel i in db.San_Imovel
    join EntityNetimoveis.San_Imovel_Caracteristica c in db.San_Imovel_Caracteristica on i.imovel_id equals c.imovel_Id
    select i;

return query.ToList();

Upvotes: 0

Win
Win

Reputation: 62260

Basically, joining is like this.

var im = 
db.San_Imovel.Join(db.San_Imovel_Caracteristica, i => i.imovel_id, a => a.imovel_Id, (i, a) => a)
.Where(a => a.Credenciada_Id.Equals(10));

Edited:

For example,

var result = db.ATable
.Where(a => a.Name == 'test')
.Join(db.BTable, a => a.Id, b => b.Id, (a, b) => a);

Upvotes: 2

Gonzalo
Gonzalo

Reputation: 45

There's a "." after Join that shouldn't be there

Upvotes: 0

Related Questions