围绕LinqToSQls工作“不支持具有本地集合的查询”例外 [英] Working around LinqToSQls "queries with local collections are not supported" exception
问题描述
所以,我想返回一个人的集合,其ID包含在本地创建的ids集合(IQueryable)
当我指定集合,我的意思是Ids集合不是来自LinqToSql查询,并已经编程创建(基于用户输入)。
我的查询如下:
var qry =从p中DBContext.People
其中Id。包含(p.ID)
选择p.ID;
这会导致以下异常...
不支持使用本地集合的查询
如何查找包含在本地创建的Ids集合中的所有ID?
是否可以使用LinqToSql?
如果Id是列表,类似,L2S将翻译成一个包含。
如果Ids是一个IQueryable,只需将它转换成列表,然后在查询中使用它。例如:
列表< int> listOfIDs = IDs.ToList();
var query =
from st in dc.SomeTable
其中listOfIDs.Contains(st.ID)
选择.....
So, I'm trying to return a collection of People whose ID is contained within a locally created collection of ids ( IQueryable)
When I specify "locally created collection", I mean that the Ids collection hasnt come from a LinqToSql query and has been programatically created (based upon user input). My query looks like this:
var qry = from p in DBContext.People
where Ids.Contains(p.ID)
select p.ID;
This causes the following exception...
"queries with local collections are not supported"
How can I find all the People with an id that is contained within my locally created Ids collection?
Is it possible using LinqToSql?
If Ids is a List, array or similar, L2S will translate into a contains.
If Ids is a IQueryable, just turn it into a list before using it in the query. E.g.:
List<int> listOfIDs = IDs.ToList();
var query =
from st in dc.SomeTable
where listOfIDs.Contains(st.ID)
select .....
这篇关于围绕LinqToSQls工作“不支持具有本地集合的查询”例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!