实体框架加入3表 [英] Entity Framework Join 3 Tables
本文介绍了实体框架加入3表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我完成了加入2表
var entryPoint = dbContext.tbl_EntryPoint
.Join(dbContext.tbl_Entry,
c => c.EID,
cm = > cm,EID,
(c,cm)=> new
{
UID = cm.OwnerUID,
TID = cm.TID,
EID = c.EID,
})。
其中(a => a.UID == user.UID).Take(10);
我希望使用 TID PK包含 tbl_Title 表,并获得
非常感谢
解决方案
我认为使用基于语法的查询将会更加简单:
var entryPoint =(从dbContext.tbl_EntryPoint中的ep
在ep.EID上加入dbContext.tbl_Entry等于e.EID
在e.TID上的dbContext.tbl_Title中加入t等于t.TID
其中e.OwnerID == user.UID
select新的{
UID = e.OwnerID,
TID = e.TID,
Title = t.Title,
EID = e.EID
})Take 10);
您应该可以添加 orderby
确保 Top(10)
返回正确的十大项目。
I'm trying to join three tables but I can't understand the method...
I completed join 2 tables
var entryPoint = dbContext.tbl_EntryPoint
.Join(dbContext.tbl_Entry,
c => c.EID,
cm => cm.EID,
(c, cm) => new
{
UID = cm.OwnerUID,
TID = cm.TID,
EID = c.EID,
}).
Where(a => a.UID == user.UID).Take(10);
I would like to include tbl_Title table with TID PK and get Title field.
Thanks a lot
解决方案
I think it will be easier using syntax-based query:
var entryPoint = (from ep in dbContext.tbl_EntryPoint
join e in dbContext.tbl_Entry on ep.EID equals e.EID
join t in dbContext.tbl_Title on e.TID equals t.TID
where e.OwnerID == user.UID
select new {
UID = e.OwnerID,
TID = e.TID,
Title = t.Title,
EID = e.EID
}).Take(10);
And you should probably add orderby
clause, to make sure Top(10)
returns correct top ten items.
这篇关于实体框架加入3表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文