如何将此 Sql 语句翻译成 Linq

How do I translate this Sql Statement to Linq

如何使用 linq 编写此查询?

select oa.*
from ord_account_error oe
join
  (select max(ord_account_error_id) [ord_account_error_id]
  from ord_account_error
  group by ord_account_id) e on oe.ord_account_error_id =   e.ord_account_error_id
 join ord_account oa on oe.ord_account_id = oa.ord_account_id
 where oe.error like '%Account in wrong status%'

查询所做的是 return 来自 ord_account 的所有行,其中 ord_account_error 中最新的相关记录包含 "Account in wrong status"。 我实际上并不需要来自 ord_account_error 的数据。它只是用于 select 来自 ord_account 的正确行,所以它 return 是我需要使用的实体。

我的最佳猜测:

 var qry = from oe in ord_account_error
            .Where(a=>a.error.Contains("Account in wrong status")) 
        join e in ord_account_error
                    .GroupBy(b=>b.ord_account_error_id)
                    .Select(grp=>grp.Max(c=>c.ord_account_error_id))
            on oe.ord_account_error_id equals  e.ord_account_error_id
        join oa in ord_account on oe.ord_account_id equals oa.ord_account_id
        select oa;