下风
不断进步才是王道!
博客园
首页
新随笔
联系
订阅
管理
随笔 - 7 文章 - 2 评论 - 7 trackbacks - 0
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
下风
阅读(271) 评论(
0
)
编辑
收藏
刷新评论
刷新页面
返回顶部
程序员问答社区,解决您的IT难题
博客园首页
博问
新闻
闪存
程序员招聘
知识库