I need cities count for each state and all columns of states table in select result set.
I have TSQL query but dont know how to tackle inner query and grouping in LINQ.
States Table
StateID,StateName,Description,Address,SectionName
Cities Table:
CityID,StateID,Address,Description
Here is TSQL query need to be converted to LINQ
declare @State varchar(100)
set @State='IL'
SELECT s.*,oCities.CityCount
from (
Select c.StateID,count(*) CityCount
from States s inner join Cities c on
s.StateID =c.StateID
where s.StateName =@State
group by c.StateID
) oCities inner join States s on oCities.StateID = s.StateID
where s.StateName =@State
Preferably in C# language but any help will be appreciated
Assuming your foreign keys have been defined and imported correctly then something like this should work
Using Linq to SQL this translates as
where p0 is your @state parameter.