asp.net-mvc – LINQ to Entities无法识别方法异常
发布时间:2020-05-22 19:35:06 所属栏目:asp.Net 来源:互联网
导读:我有这样的事情 SecuritySearcher sc = new SecuritySearcher();Dictionarystring, bool groupsMap = sc.GetUserGroupMappings(domainName, currentUser, distGroups.ToList());IQueryableHotelTravel groupq =
|
我有这样的事情 SecuritySearcher sc = new SecuritySearcher();
Dictionary<string,bool> groupsMap =
sc.GetUserGroupMappings(domainName,currentUser,distGroups.ToList());
IQueryable<HotelTravel> groupq =
(from hotel in qHs
join hp in qHps on hotel.HotelTravelId equals hp.HotelTravelId
where !string.IsNullOrEmpty(hp.GroupName)
&& groupsMap.ContainsKey(hp.GroupName)
&& groupsMap[hp.GroupName] == true
select hotel);
在执行Linq语句时,它正在抛出异常说法 解决方法为了将表达式转换为数据库查询,数据库必须以某种方式知道字典的内容并有办法从查询中访问它. SQL中没有字典机制,但这并不重要,因为您不需要字典,因为您只是在寻找值为某个常量的键.您可以将该组密钥转换为列表,并查看该列表是否包含您要查找的内容:var groupsList = (from kvp in groupsMap // find all keys in groupsMap
where kvp.Value == true // where the value is set to True
select kvp.Key).ToList();
IQueryable<HotelTravel> groupq =
from hotel in qHs
join hp in qHps on hotel.HotelTravelId equals hp.HotelTravelId
where !string.IsNullOrEmpty(hp.GroupName)
&& groupsList.Contains(hp.GroupName)
select hotel;
我怀疑你实际上并没有将空字符串作为字典中的键,这意味着你可以摆脱IsNullOrEmpty调用,只需要在groupsList.Contains(hp.GroupName)中. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 为什么使用隐藏的字段?
- asp.net-mvc – User.IsInRole不起作用
- asp.net-mvc – ASP.Net MVC如何确定用户是否可以访问一个U
- asp.net – Visual Studio 2008,2010或2012(v11)是否写入使
- asp.net-mvc – ELMAH – 使用自定义错误页面收集用户反馈
- 如何从asp.net调用Windows服务
- ASP.NET MVC Web API2 AngularJS授权和身份验证
- asp.net-mvc – 在Azure中预编译ASP.NET MVC项目(不与Web部
- asp-classic – 用于新的Web应用程序的经典ASP与PHP
- asp.net-mvc – 解耦Microsoft.AspNet.Identity.*
推荐文章
站长推荐
- asp.net – 加密ASP .NET 2.0和SQL Server 2005中
- asp.net – 如何在Button Click事件上调用此Jque
- asp.net – 在所选数据源上找不到具有该名称的字
- asp.net-mvc – MVC:如何将文件上传和其他表单字
- 如何获取asp.net Windows身份验证中的用户详细信
- asp.net-mvc – MVC 6:如何使用RESX文件?
- asp.net-mvc-3 – 如何在本地测试时禁用elmah发送
- asp.net-mvc-4 – 会话到期后重定向到特定页面(M
- asp.net-mvc-3 – 使用jQuery验证货币字段的客户
- asp.net-mvc-4 – 我似乎没有安装SignalR与MVC4
热点阅读
