如何与Entity Framework进行联接

时间:2012-08-24 18:13:43

标签: linq entity-framework

如何与另一个Join进行Entity

我有这个,

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

我希望JOINSan_Imovel_Caracteristica。主键和外键称为Imovel_Id

我试试这个

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));

但这是错误的代码。语法错误。

3 个答案:

答案 0 :(得分:2)

基本上,加入是这样的。

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));

编辑:

例如,

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

答案 1 :(得分:0)

有一个“。”加入后不应该在那里

答案 2 :(得分:0)

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();