会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
下风
不断进步才是王道!
博客园
首页
新随笔
联系
订阅
管理
Linq to Entities Contains 异常,换一种方法实现
报异常的代码如下:
Code
IList
<
string
>
list
=
new
List
<
string
>
();
list.Add(
"
00002
"
);
list.Add(
"
00003
"
);
list.Add(
"
00006
"
);
list.Add(
"
00004
"
);
IList
<
Customer
>
clist
=
(from cust
in
ctx.Customer
where
list.ToArray().Contains(cust.CustomerCode) select cust).ToList
<
Customer
>
();
换一种方法
Code
IList
<
string
>
list
=
new
List
<
string
>
();
list.Add(
"
00002
"
);
list.Add(
"
00003
"
);
list.Add(
"
00006
"
);
list.Add(
"
00004
"
);
string
codes
=
string
.Join(
"
,
"
, list.Select(c
=>
"
'
"
+
c
+
"
'
"
).ToArray());
string
query
=
"
SELECT VALUE C FROM Customer AS C WHERE C.CustomerCode IN {
"
+
codes
+
"
}
"
;
ObjectQuery
<
Customer
>
custobject
=
new
ObjectQuery
<
Customer
>
(query, ctx);
IList
<
Customer
>
clist
=
custobject.ToList
<
Customer
>
();
posted on
2009-08-11 17:33
下风
阅读(
473
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部