LINQ to sql 中联表(对象)查询问题,比较难!
news 表结构 :
id         type            txt
---------------------------------
1         200         abcdd
2         2200        abcdd2
3         320         abcdd33
4         110         abcdd3
5         200         abcdd3
6         110         abcdd4
现在要用LINQ TO SQL 查出TYPE是为 int[] itype={200,320} 的数据(注意itype这个数据是动态产生的)
我要的结果是
id         type            txt
---------------------------------
1         200         abcdd
3         320         abcdd33
5         200         abcdd3
如果int[] itype={320,110}
结果为:
id         type            txt
---------------------------------
3         320         abcdd33
4         110         abcdd3
6         110         abcdd4
请各路仙家要考虑性能~
------解决方案--------------------
又写错啦。。。
public IQueryable <news> FindNews(int[] arg)  
{  
   return from n in dataContext.news where arg.contains(n.type) select n;  
}
------解决方案--------------------SQL code
int[] itype={200,320};
可以把这个拼接成字符串STR='200,302'
然后可以利用SQL查询
SELECT * FROM TB WHERE CHARINDEX(','+LTRIM(TYPEID)+',',','+STR+',')>0
------解决方案--------------------
首先取到news 表(假设变量名为newsTable)
var result = from item in itype
                      from newsRow in newsTable
                      where newsRow.type = item
                      select newsRow