我是 LINQ 的新手,我目前正在查看用户所属的所有组织,以确保他们有权在表单上执行各种操作。
看起来像这样:
//loop through all user orgs to see if what they selected, they have access to
foreach (OrgPermission userOrg in user.orgs)
{
//get the org permissions for the selected org
if ((ddlOrg.SelectedValue == (userOrg.Org.orgCode + "-" + userOrg.Org.orgSubCode)))
{
if (userOrg.type.Contains("3") || userOrg.type.Contains("00"))
{
/
/do something here.
}}}
我正在尝试摆脱循环。好像用户有很多组织它需要一点时间来运行,我正在尝试优化应用程序运行时间。
我尝试了以下方法:
bool has = user.orgs.Any(cus => cus.Org.orgCode + "-" + cus.Org.orgSubCode == ddlOrg.SelectedValue);
如您所见,ddlOrg 下拉值采用 org-suborg 格式。但我总是假的。
我还想保存结果,而不是保存在 bool 中,但可能保存为它找到的单个 user.ORG,以便我可以使用它来检查权限和其他内容。
我在正确的轨道上吗?有人可以指出我正确的方向。