asp.net-mvc – LINQ to Entities无法识别方法异常
发布时间:2020-12-15 20:39:55 所属栏目:asp.Net 来源:网络整理
导读:我有这样的事情 SecuritySearcher sc = new SecuritySearcher();Dictionarystring,bool groupsMap = sc.GetUserGroupMappings(domainName,currentUser,distGroups.ToList());IQueryableHotelTravel groupq = (from hotel in qHs join hp in qHps on hotel.Ho
我有这样的事情
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)中. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- IIS7上的ASP.NET应用程序 – 在iisreset启动后非常慢
- asp.net – 通过调用.ashx页面下载文件
- asp.net-web-api – Web API中的Actions和QueryString参数
- asp.net – 何时使用Request.RegisterForDispose?
- asp.net-mvc-5 – EntityFramework.SqlServer.dll中出现’S
- Azure Apps EasyAuth声称使用.NET Core
- 武装你的WEBAPI-OData入门
- asp.net – 如何解决错误:当应用程序未在UserInteractive模
- ASP.NET MVC编辑器模板和Html.EditorFor(…) – 如何消除类
- Asp.net视图状态MAC的验证失败
推荐文章
站长推荐
- asp.net – COM异常 – TYPE_E_CANTLOADLIBRARY?
- 如何从ASP.NET中的soap异常中提取内部异常?
- asp.net-mvc-3 – MVC 3(Razor) – 使用Button事
- asp.net-mvc-3 – ASP .Net MVC 3不引人注目的客
- asp.net – 错误4005表单身份验证失败 – 提供的
- asp.net – 在非关系数据库中创建视图
- asp.net – 餐厅后端系统和.Net
- asp.net-mvc – ASP.net MVC验证钩
- ASP.NET页面授权……你是怎么做到的?
- asp.net-mvc – 需要为ASP.NET mvc部署哪些文件?
热点阅读