我有一个字典,我想在SQL查询中像IN子句一样使用它。
我有一个Linq-To-SQL查询,我想使用这个字典的键来检查查询行中的字段。
例如:
bool result = DataContext.Table.Any(res => MyDictionary.ContainsKey(res.field1));
实际上,这类似于
exists(select * from Table where field1 in (select id from DictionaryKeys))
其中DictionaryKeys
将是将键扩展到自己的表中的扩展。
不幸的是,我得到了
System.NotSupportedException was unhandled
Message="Method 'Boolean ContainsKey(System.String)' has no supported translation to SQL."
Source="System.Data.Linq"
我理解这个错误,但是我很难想到另一种解决方案。
编辑:我正在连接到SQL 2005。看起来这是一个连接提供程序的问题,因为Marc建议转换为List对我不起作用。
有任何想法吗?