首页 新闻 会员 周边

在使用LINQ查询中报这个错误" 类型“System.String[]”不支持比较运算符

0
悬赏园豆:10 [已关闭问题] 关闭于 2009-05-01 19:02

我的查询语句是这么写的:

            return from ae in Context.GetTable<Article>()
                   let tagids = ae.tagids.Split(',')
                   where ae.tagids != null
                   from temp in tagids
                   where temp == tagid.ToString()
                   select ae;

 

Article表有个tagids字段,存放每个tag对应的ID,如1,2,3,23等,现在要查询包含有tag ID为3的文章...

问题补充: tagid不是数组,是int
墙头草的主页 墙头草 | 初学一级 | 园豆:6
提问于:2009-05-01 17:09
< >
分享
所有回答(4)
0

tagid是个数组,你这样比较当然出错

songzibin | 园豆:140 (初学一级) | 2009-05-01 17:16
0

            return from ae in Context.GetTable<Article>()
                   let tagids = ae.tagids.Split(',')
                    from temp in tagids
                   where temp == tagid.ToString()
                   select ae;

nulldust | 园豆:205 (菜鸟二级) | 2009-05-01 18:14
0

楼上的视乎也不行

melody&bobo | 园豆:176 (初学一级) | 2011-11-29 16:10
0

如果是外键做了关系表,直接查询即可 where(ae=>ae.tag.Any(y=>y==3))

如果是用一个字段存了逗号分隔的id,可以用where(x=>x.IndexOf(","+ae.tag+",")>-1)

这样使用的前提是你再字段中存的是,1,2,3,4,前后都有,这样的形式,否则1,11,121,111这些数据查出来就不准确了

czcz1024 | 园豆:222 (菜鸟二级) | 2012-12-21 09:27

where(x=>x.IndexOf(",3,")>-1)应该是这样,3是你需要查的

支持(0) 反对(0) czcz1024 | 园豆:222 (菜鸟二级) | 2012-12-21 09:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册