实体框架连接 3 个表 [英] Entity Framework Join 3 Tables
本文介绍了实体框架连接 3 个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试连接三个表,但我无法理解该方法...
I'm trying to join three tables but I can't understand the method...
我完成了 2 个表的连接
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);
我想包含 tbl_Title 表和 TID PK 并获得 Title 字段.
I would like to include tbl_Title table with TID PK and get Title field.
非常感谢
推荐答案
这是未经测试的,但我相信语法应该适用于 lambda 查询.当您使用此语法连接更多表时,您必须进一步深入研究新对象以获取您想要操作的值.
This is untested, but I believe the syntax should work for a lambda query. As you join more tables with this syntax you have to drill further down into the new objects to reach the values you want to manipulate.
var fullEntries = dbContext.tbl_EntryPoint
.Join(
dbContext.tbl_Entry,
entryPoint => entryPoint.EID,
entry => entry.EID,
(entryPoint, entry) => new { entryPoint, entry }
)
.Join(
dbContext.tbl_Title,
combinedEntry => combinedEntry.entry.TID,
title => title.TID,
(combinedEntry, title) => new
{
UID = combinedEntry.entry.OwnerUID,
TID = combinedEntry.entry.TID,
EID = combinedEntry.entryPoint.EID,
Title = title.Title
}
)
.Where(fullEntry => fullEntry.UID == user.UID)
.Take(10);
这篇关于实体框架连接 3 个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文