1

How can I convert the following SQL select statement to Linq?

SELECT u.Name FROM User u AS DDC
INNER JOIN Country c ON c.UserId = u.UserId
INNER JOIN (
     SELECT AddressId,
            Address, 
            PC, 
        FROM AddressTbl a
    WHERE a.CountryId = 1
) AS Addresses ON Addresses.AddressId= u.AddressId

WHERE 

u.UserIs = @UserId AND
Addresses.AddressId= @AddressId

Any good reading references?

Stavros
  • 5,802
  • 13
  • 32
  • 45
  • This is a question that is relevant to you but will never be of interest to anyone else. It would be better to ask about the T-SQL structures that give you trouble. eg. the subquery join. – Peter Jan 06 '12 at 12:32
  • thanks. I made the sql more simple.. – Stavros Jan 06 '12 at 12:46

2 Answers2

2
from u in Users join 
     c in Country on  c.UserId equals u.UserId
     join a in Address on a.AddressId equals u.AddressId     
where a.CountryId == 1
select u.Name
Jahan Zinedine
  • 14,616
  • 5
  • 46
  • 70
0

You can try this out http://www.sqltolinq.com/

user1120193
  • 252
  • 3
  • 11