将SQL select语句转换为Linq

时间:2012-01-06 12:27:36

标签: linq linq-to-sql sql-to-linq-conversion

如何将以下SQL select语句转换为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

任何好的阅读参考?

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

你可以尝试一下 http://www.sqltolinq.com/