asp.net-mvc – LINQ to Entities无法识别方法异常
发布时间:2020-10-19 13:36:53 所属栏目: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-mvc – 如何在ASP.NET MVC4中使用具有唯一标识符UR
- 如何使用Fluent Nhibernate中的Automapping进行OR Mapping映
- 充分利用ASP.NET的三种缓存提高站点性能的注意方法
- asp.net-mvc – 带有lambda表达式的ASP.net MVC Action URL
- asp.net后台cs中的JSON格式变量在前台Js中调用方法(前后台示
- ASP.NET 清除模式窗口数据缓存的操作方式
- asp.net-mvc – UpdateModel前缀 – ASP.NET MVC
- 将ASP.NET应用程序本地化为普通话
- asp.net-mvc – asp.net mvc博客引擎
- asp.net – 我可以通过编程方式禁用更新面板吗?
推荐文章
站长推荐
- asp.net-mvc-4 – Can Castle Windsor可用于在AS
- 这是一个bug?浮动操作被视为整数
- asp.net – 如何正确地大写希腊字在.NET?
- asp.net类序列化生成xml文件实例详解
- asp.net-mvc – ASP.NET MVC – RequireJS最佳的
- Autofac和ASP.NET Web API ApiController
- asp.net-core – ASP.Net核心maxUrlLength
- asp.net-mvc – 带有lambda表达式的ASP.net MVC
- asp.net-mvc – 如何将行的模型从Kendo Grid传递
- asp.net 大文件上传控件
热点阅读