如何使用Entity framework和linq从各种连接表中获取列?
我的sql语句如下:
SELECT
j1.Username, j2.points, j3.address1
FROM
users j1
INNER JOIN points j2 on j1.userId = j2.UserId
INNER JOIN addresses j3 on j3.userId = j1.UserId
所以我很困惑如何将其转换为EF / linq查询,该查询返回连接表/实体中的列。
答案 0 :(得分:0)
你肯定应该在提出问题之前发布你尝试过的内容......
看起来应该是这样的:
var results = from j1 in context.users
join j2 in context.points on j1.UserId equals j2.UserId
join j3 in context.addresses on j1.UserId equals j3.UserId
select new { j1.Username, j2.points, j3.address1 }
它将为您提供一组包含3列值的匿名对象。