在LINQ to Entity查询中连接数组 [英] Joining arrays in LINQ to Entity queries

查看:106
本文介绍了在LINQ to Entity查询中连接数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对LINQ很新。我想要做的是模拟IN查询情况。我有我的IN列表形式一个字符串数组(或List< string>无论如何),我想在我的L2E查询中使用它。类似于以下内容

List< string> roles = LoginManager.GetRoleMemberships();

var k =来自db.ACTIVITY_CENTER_ASSIGN中的aca
加入角色aca.APP_GROUP.GROUP_ID等于r
select aca.ACTIVITY_CENTER;
< br> centers = k.ToList< ACTIVITY_CENTER>();

代码编译但最后一行在运行时抛出异常。

"无法创建类型的常量值'System .Collections.Generic.IEnumerable`1' 。在此上下文中仅支持原始类型(例如Int32,String和Guid')。"

任何想法我该如何做这样的事情。

解决方案

Hello,

不支持驻留在服务器上的数据与驻留在客户端上的数据之间的JOIN操作。我们正在努力支持Contains LINQ查询运算符,作为在未来版本的Entity Framework中解决IN()场景的一种方法。同时,以下线程描述了一种解决方法:

http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/095745fe-dcf0-4142-b684-b7e4a1ab59f0/

希望这个帮助,结果,迭

I am fairly new to LINQ. What I trying to do is to simulate an IN query situation. I have my IN list in form a string array (or List<string> whatever) and I want to use it in my L2E query. Something like following

List<string> roles = LoginManager.GetRoleMemberships();

                var k = from aca in db.ACTIVITY_CENTER_ASSIGN
                        join r in roles on aca.APP_GROUP.GROUP_ID equals r
                        select aca.ACTIVITY_CENTER;

                centers = k.ToList<ACTIVITY_CENTER>();

The code compiles but last line throws following exception at run time.

"Unable to create a constant value of type 'System.Collections.Generic.IEnumerable`1'. Only primitive types ('such as Int32, String, and Guid') are supported in this context."

Any ideas how can I do something like this.

解决方案

Hello,

Performing a JOIN operation between data that resides on the server and data that resides on the client is not supported. We are working on supporting the Contains LINQ query operator as a way to address the IN() scenario in a future version of Entity Framework. In the meanwhile, the following thread describes a workaround:

http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/095745fe-dcf0-4142-b684-b7e4a1ab59f0/

Hope this helps,
Diego


这篇关于在LINQ to Entity查询中连接数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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