您好我试图复制这个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);
它没有显示任何错误,但它没有返回任何数据。
答案 0 :(得分:6)
你在第三行有错误:
join c in db.areas on b.id equals c.id
应该是
join c in db.areas on b.areas_id equals c.id