【发布时间】:2015-07-31 03:28:27
【问题描述】:
大家好
我有两个 Linq 查询如下
var sub_query = from x in db.table
where
x.item1 == "abcd"
select new
{
x.Item2 //is a string
}
var query = from y in db2.table
where
sub_query.ToList().Contains(new {y.item2}) //error here
select new { y.element }
这行不通
它无法识别 y 中的任何内容并引发匿名错误 y.item2 is a string
我也直接尝试了sub_query.Containsinsidequery,但同样的错误
编辑(给出错误)
最好的重载方法匹配 'System.Collections.Generic.List.Contains(AnonymousType#1)' 有一些无效的参数
PS : 当我构建解决方案时,错误消失了,例如,如果删除逗号 (;) 并添加一个新的逗号,错误又回来了
【问题讨论】:
-
错误信息到底是什么?