简体   繁体   English

LINQ to Entities不支持错误,方法

[英]Error, method not supported by LINQ to Entities

Why I am getting this error: 为什么我收到此错误:

The method 'Single' is not supported by LINQ to Entities. LINQ to Entities不支持“Single”方法。 Consider using the method 'First' instead. 请考虑使用“First”方法。

           public ActionResult Details(int id)
Line 27:   {              
             var result = (from d in _db.MovieSet
Line 29:     where d.Id == id
Line 30:     select d).Single();
            //
            //
           } 

Code compiles safe, but only breaks if call is made to the respective section. 代码编译安全,但只有在调用相应部分时才会中断。 I am new to LINQ, therefore do not know which methods are for LINQtoSQL or LINQtoEntities. 我是LINQ的新手,因此不知道哪些方法适用于LINQtoSQL或LINQtoEntities。 This means more errors! 这意味着更多错误! We cannot remember all methods this way. 我们不记得所有这些方法。

My question is, if there are limitations to the methods applicable to certain types / scenarios, why do they appear in Intellisense? 我的问题是,如果适用于某些类型/场景的方法存在局限性,为什么它们出现在Intellisense中?

EDIT: Any work-around / technique helpful to have an idea if one is supported ? 编辑:任何解决方法/技术有助于了解是否支持?

In the case of LINQtoSQL / Entities, the queries are all broken down into expression trees which are then passed to the provider APIs. 对于LINQtoSQL / Entities,查询全部细分为表达式树,然后传递给提供者API。 The providers cannot provide compile time information about the trees they do or do not support because there is no syntactic difference. 提供者无法提供有关他们支持或不支持的树的编译时信息,因为没有语法差异。 The only choice is for them to provide runtime data. 唯一的选择是让他们提供运行时数据。

For example once in expression tree form, both the Single and First appear as a MethodCallExpression instance. 例如,在表达式树形式中,Single和First都显示为MethodCallExpression实例。

Microsoft has a complete list of supported and unsupported methods in Linq to Entities. Microsoft拥有Linq to Entities 中支持和不支持的方法的完整列表 That's where to go to find out this information. 这是找到这些信息的地方。

You'll notice that the Single and SingleOrDefault methods are in fact listed as "not supported" in the section on Paging Methods. 您会注意到SingleSingleOrDefault方法实际上在“分页方法”一节中列为“不支持”。

As Jared pointed out, the compiler does not know at compile time which provider you are using, so it has no way to enforce compile-time safety of extension methods that the provider may or may not implement. 正如Jared指出的那样,编译器在编译时不知道您正在使用哪个提供程序,因此它无法强制提供程序可能会或可能不会实现的扩展方法的编译时安全性。 You'll have to rely on the documentation instead. 您将不得不依赖文档。

Unfortunately, it's yet another indication of both the r elative immaturity of EF and the Object Relational Impedance Mismatch . 不幸的是,这又是EF对象关系阻抗不匹配的另一个表现。

Documentation is your friend if you choose to go this route. 如果您选择这条路线, 文档就是您的朋友。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 方法内的where子句中出现错误“ LINQ to Entities不支持LINQ表达式节点类型'Invoke'” - Error “The LINQ expression node type 'Invoke' is not supported in LINQ to Entities” in where clause inside the method LINQ错误 - 不支持方法'Sum' - LINQ error - The method 'Sum' is not supported 错误:LINQ to Entities不支持LINQ表达式节点类型'ArrayIndex' - Error: The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities EF - LINQ to Entities不支持 - EF - not supported in LINQ to Entities 成员“在LINQ to Entities中不受支持” - Member is “not supported in LINQ to Entities” LINQ to Entities不支持 - Not supported in LINQ to Entities LINQ to Entities不支持'ArrayIndex' - 'ArrayIndex' is not supported in LINQ to Entities LINQ to Entities不支持“ Ticks” - 'Ticks' is not supported in LINQ to Entities 分页错误:方法“跳过”仅支持 LINQ to Entities 中的排序输入。 方法 'OrderBy' 必须在方法 'Skip' 之前调用 - Paging Error :The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip' 投影并调用方法,“ LINQ to Entities不支持指定的类型成员'Member'” - Projection and calling a method, “The specified type member 'Member' is not supported in LINQ to Entities”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM