這裏是我的SQL查詢:如何SQL查詢轉換爲Lambda表達式
SELECT
UserName,
IsApproved
FROM aspnet_Users u
INNER JOIN aspnet_Membership m
ON u.UserId = m.UserId
任何人可以幫助我如何與lambda表達式寫?
這裏是我的SQL查詢:如何SQL查詢轉換爲Lambda表達式
SELECT
UserName,
IsApproved
FROM aspnet_Users u
INNER JOIN aspnet_Membership m
ON u.UserId = m.UserId
任何人可以幫助我如何與lambda表達式寫?
試試這個..
from u in context.aspnet_Users
join m in context.aspnet_Membership on u.UserId equals m.UserId select new { u.UserName, m.IsApproved};
from u in aspnet_Users
join m in aspnet_Membership on u.UserId equals m.UserId
select new { u.UserName, m.IsApproved };
加入ON錯過。 – valex
@valex謝謝我修復 –
您可以使用JOIN
與Lambda表達式這樣的事情,
var result = aspnet_Users
.Join(aspnet_Membership,
u => u.UserId,
m => m.UserId,
(u, m) => new
{
UserName = u.UserName,
IsApproved = u.IsApproved
}
);
一個怎麼樣這個查詢:
選擇用戶名, is asproved from aspnet_Users你好 inner join aspnet_Membership m on u.UserId = m.UserId 其中u.UserName = @UserName
在這種情況下,放哪裏? @UserName的是,我在 公衆的ActionResult UserActivation(用戶名字符串)定義字符串參數 { ... }
如果會是這樣,將會怎樣?選擇用戶名,從aspnet_Users IsApproved ù 內上u.UserId加入aspnet_Membership米= m.UserId 其中u.UserName = @UserName – Biljana
這將是,從aspnet_Users選擇u.UserName,m.IsApprovedû內部聯接aspnet_Membership米上u.UserId = m.UserId其中u.UserName = @UserName –