gpt4 book ai didi

c# - LINQ语法问题

转载 作者:行者123 更新时间:2023-11-30 14:17:32 25 4
gpt4 key购买 nike

我有这个原始 SQL,我需要在 LINQ 中重写:

SELECT 
luProfiles.luProfileID,
luProfiles.ProfileName,
NoOfRights = (SELECT Count(pkProfileRightsID) FROM tblProfileRights WHERE fkProfileID = luProfileID)
FROM luProfiles
WHERE luProfiles.ProfileName LIKE ...

我已经在 LINQ 中完成了大部分工作,但我不确定如何将 NoOfRights 部分添加到我的 LINQ 中。这是我到目前为止所做的:

return from p in _database.LuProfiles
where p.ProfileName.ToLower().StartsWith(strProfile.ToLower())
select p;

谁能告诉我在我的 LINQ 中包含 NoOfRights 部分的正确语法?

最佳答案

from p in _database.LuProfiles
let NoOfRights = (from r in database.tblProfileRights
where r.fkProfileID == p.luProfileID
select r).Count()
where p.ProfileName.ToLower().StartsWith(strProfile.ToLower())
select new
{
p.luProfileID,
p.ProfileName,
NoOfRights
};

关于c# - LINQ语法问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5743679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com