LINQ to Entities多重连接 [英] LINQ to Entities multiple join

查看:48
本文介绍了LINQ to Entities多重连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hi im trying to replicate this mysql query

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);

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

it doesn't show any error but it's not returning any data.

推荐答案

第三行出现错误:

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

应该是

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

这篇关于LINQ to Entities多重连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆