1

Possible Duplicate:
how to do subquery in LINQ

I have a SQL Server 2008 query:

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;

I need to convert it to C# linq statement. Please let me know how could I do it.

Community
  • 1
  • 1
user466663
  • 815
  • 4
  • 18
  • 40

1 Answers1

4
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 };
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459