首页 新闻 会员 周边

不支持引用非标量变量

0
悬赏园豆:50 [已关闭问题]
以下是MSDN上面的解析,不太明白“非标量变量“”?


不支持在查询中引用非标量变量(如实体)。在此类查询执行时,会引发 NotSupportedException 异常,并显示以下消息:“无法创建类型为‘EntityType’的常量值。此上下文中仅支持基元类型(‘如 Int32、String 和 Guid’)。”[Unable to create a constantvalue of type 'Closure type'. Only primitive types ('such as Int32,String, and Guid') are supported in this context.]

说明说明:

支持引用标量变量的集合。

using (AdventureWorksEntities AWEntities = new AdventureWorksEntities())
{
Contact contact = AWEntities.Contacts.FirstOrDefault();

// Referencing a non-scalar closure in a query will
// throw an exception when the query is executed.
IQueryable<string> contacts = from c in AWEntities.Contacts
where c == contact
select c.LastName;

try
{
foreach (string name in contacts)
{
Console.WriteLine("Name: ", name);
}
}
catch (NotSupportedException ex)
{
Console.WriteLine(ex.Message);
}
}


问题补充: 我是用entity framework遇到的问题,FRAMEWORK4+EF4+VS2010
@GB的主页 @GB | 初学一级 | 园豆:190
提问于:2010-06-15 15:43
< >
分享
其他回答(1)
0

就是说你出现在 where 中的这些变量必须是原始类型变量,不可以是你自定义的类或结构。

非标量 英文为 Non-Scalar,意思是不能标注数量的。原始类型比如 int ,.net framework 可以比较其大小,数量,但如果你自定义一个类,用 == , > 这些比较操作符,.net framework 就无法进行比较了。

eaglet | 园豆:17139 (专家六级) | 2010-06-16 08:01
0

在SQL2008的查询优化架构中,有几个非常重要的概念:

统计(Statistics)、标量评估(Cardinality estimation)和成本(costing)

本人正整理这一部分的读书笔记,敬请关注:
http://www.cnblogs.com/downmoon/archive/2010/06/06/1742318.html

也可以在msdn查找:
http://msdn.microsoft.com/en-us/library/ms175933.aspx

邀月 | 园豆:25475 (高人七级) | 2010-06-17 08:07
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册