Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将带有子查询的sql查询转换为linq语句_C#_Sql_Linq_Sql Server 2008 - Fatal编程技术网

C# 将带有子查询的sql查询转换为linq语句

C# 将带有子查询的sql查询转换为linq语句,c#,sql,linq,sql-server-2008,C#,Sql,Linq,Sql Server 2008,可能重复: 我有一个SQL Server 2008查询: select account_hcc_id, account_name from [ACCOUNT_HISTORY_FACT] where TOP_ACCOUNT_KEY = (select TOP 1 TOP_ACCOUNT_KEY from ACCOUNT_HISTORY_FACT where ac

可能重复:

我有一个SQL Server 2008查询:

select 
    account_hcc_id, account_name 
from 
    [ACCOUNT_HISTORY_FACT] 
where 
     TOP_ACCOUNT_KEY = (select TOP 1 TOP_ACCOUNT_KEY 
                        from ACCOUNT_HISTORY_FACT 
                        where account_hcc_id = '3362') 
     and ACCOUNT_LEVEL = 1;
我需要将其转换为C#linq语句。请告诉我怎么做

from ahf in db.ACCOUNT_HISTORY_FACT
where ahf.ACCOUNT_LEVEL == 1 &&
      ahf.TOP_ACCOUNT_KEY == db.ACCOUNT_HISTORY_FACT
                               .Where(x => x.account_hcc_id == "3362") 
                               .Select(x => x.TOP_ACCOUNT_KEY)
                               .FirstOrDefault() 
select new { ahf.account_hcc_id, ahf.account_name };