首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

LINQ to sql 中联表(对象)查询有关问题,比较难

2012-02-22 
LINQ to sql 中联表(对象)查询问题,比较难!news 表结构 :idtypetxt---------------------------------1200

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

热点排行