I have some thing like this
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);
While executing Linq statement it is throwing exception saying
LINQ to Entities does not recognize the method ‘Boolean ContainsKey(System.String)’ method, and this method cannot be translated into a store expression.
In order to translate your expression into a database query, the database would somehow have to know the contents of your dictionary and have a way to access it from the query. There is no dictionary mechanism in SQL, but that doesn’t matter because you don’t need a dictionary because you’re just looking for keys whose value is a certain constant. You can turn that set of keys into a list and see if that list contains what you’re looking for:
I suspect that you don’t actually have the empty string as a key in your dictionary, though, which means you can get rid of the
IsNullOrEmptycall and just havewhere groupsList.Contains(hp.GroupName).