2

嗨我试图复制这个 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);

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

4

1 回答 1

6

您在第三行有错误:

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

应该

join c in db.areas on b.areas_id equals c.id
于 2013-06-07T07:15:30.277 回答