gpt4 book ai didi

c# - LINQ to Entities 多重连接

转载 作者:行者123 更新时间:2023-11-29 01:22:14 25 4
gpt4 key购买 nike

您好,我正在尝试复制此 mysql 查询

SELECT a.id, a.title, a.description, a.categories_id, c.name, d.title
FROM ads AS a
INNER JOIN locations AS b
ON a.locations_id = b.id
INNER JOIN areas AS c
ON b.areas_id = c.id
INNER JOIN categories AS d
ON a.categories_id = d.id
WHERE a.title LIKE '%mini%'
AND c.name = 'Fyn'
LIMIT 10

这是在 LINQ 中

var query = (from a in db.ads
join b in db.locations on a.locations_id equals b.id
join c in db.areas on b.id equals c.id
join d in db.categories on a.categories_id equals d.id
where a.title.Contains(searchQuery) && c.name.Equals(area)
select new {
a.id,
a.title,
a.description,
category = d.title
}).Take(10);

它没有显示任何错误,但没有返回任何数据。

最佳答案

你在第三行有错误:

join c in db.areas on b.id equals c.id

应该是

join c in db.areas on b.areas_id equals c.id

关于c# - LINQ to Entities 多重连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16978275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com