I have the same problem where I want to query an HStore field in a PostgreSQL table using only LINQ.
Previously I switched to SQL in LINQPad and dealt with the problem that way. But LINQPad can cope quite well if you materialise the query using a .ToList()
or something before doing the querying of the HStore field.
For example, I have a 'Survey' table where the AssetId
field is a simple text field that 'describes' a relationship to another table, and then a Values
HStore field with the results of the survey that could include several different fields. So if I want to look for all surveys for 'ROAD's with a 'number_lanes' value, then my LINQ query was:
AssetsSurveys.Where (a => a.AssetId.StartsWith("ROAD-")).ToList().Where(a => a.Values.ContainsKey("number_lanes"))
The .ToList()
in the middle results in the HStore field being materialised as a Dictionary
that can then be easily queried.