本地序列不能在LINQ可以用于执行SQL查询操作中除包含运算符() [英] Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator

查看:691
本文介绍了本地序列不能在LINQ可以用于执行SQL查询操作中除包含运算符()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用LINQ在我的项目,我的code是:

i use LINQ in my project and my code is :

var SE = from c in Shop.Sections
                    join c1 in obj.SectionObjects on c.SectionId equals c1.SectionId
                    select c;

 dataGridView1.DataSource = SE;

但我面对这行误差 dataGridView1.DataSource = SE; 结果
错误消息是:

but i face this error in line dataGridView1.DataSource = SE;
error message is :

本地序列不能在LINQ可以用于除载有()运算符SQL执行查询操作的。

Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator.

感谢您的帮助。

推荐答案

您不能使用SQL源和本地源之间的联接。你需要把SQL数据到内存中,然后才能加入他们的行列。在这种情况下,你没有真正做一个连接,因为你只需要在第一个集合的元素,你想要的是一个的选择... ...在哪里在SELECTID 的查询结果,您可以获得使用包含方法。

You can't use a Join between a SQL source and a local source. You'll need to bring the SQL data into memory before you can join them. In this case, you're not really doing a join since you only take the elements from the first collection, what you want is a select...where...selectid in query, which you can get using the Contains method.

 var SE = Shop.Sections.Where( s => obj.SectionObjects
                                       .Select( so => so.SectionId )
                                       .Contains( s.SectionId ))
                       .ToList();

转换为

select * from Sections where sectionId in (...)

其中IN子句来自IDS的局部对象的集合中的列表中的值。

where the values for the in clause come from the list of ids in the collection of local objects.

这篇关于本地序列不能在LINQ可以用于执行SQL查询操作中除包含运算符()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆