我试图弄清楚为什么在C#中使用Linq将4个表连接在一起时速度很慢。此外,有两个相同的表wp_posts
。我想知道我是否可以减少表格,它可能会更快。我正在使用MySQL。
var results = from a in _newsEntities.wp_posts
join b in _newsEntities.wp_postmeta
on a.ID equals b.post_id
join c in _newsEntities.wp_posts
on b.meta_value equals c.ID.ToString()
join d in _newsEntities.wp_users on a.post_author equals d.ID
where a.post_status == "publish" &&
a.post_type == "post" &&
b.meta_key == "reporter_name"
select new
{
Id = a.ID,
Status = a.post_status,
Content = a.post_content,
ReporterId = c.post_content,
ReporterName = c.post_title,
DateCreated = a.post_date,
DateModified = a.post_modified,
AuthorId = a.post_author,
AuthorName = d.display_name
};