错误,方法不LINQ支持实体 [英] Error, method not supported by LINQ to Entities

查看:155
本文介绍了错误,方法不LINQ支持实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我得到这个错误:

Why I am getting this error:

的方法'单'不支持LINQ到实体。考虑使用方法第一来代替。

The method 'Single' is not supported by LINQ to Entities. Consider using the method 'First' instead.

           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();
            //
            //
           } 



代码编译安全,但只有当调用到相应的部分做出突破。我是新来的LINQ,所以不知道哪些方法是LINQtoSQL或LINQtoEntities。这意味着更多的错误!我们不能记住所有方法这种方式。

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. 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?

编辑:任何变通办法/技术的有益的,如果一个是支持有一个想法

Any work-around / technique helpful to have an idea if one is supported ?

推荐答案

微软的支持和不支持的方法的完整列表在LINQ to实体。这是去哪里找这方面的信息。

Microsoft has a complete list of supported and unsupported methods in Linq to Entities. That's where to go to find out this information.

您会注意到的SingleOrDefault 方法其实列为不支持在分页方法的部分。

You'll notice that the Single and SingleOrDefault methods are in fact listed as "not supported" in the section on Paging Methods.

由于贾里德指出的那样,编译器不知道你正在使用哪个提供商编译时间,所以它没有办法执行的,该供应商可能会或可能不会实现扩展方法编译时的安全性。你必须依靠而不是文件上。

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. You'll have to rely on the documentation instead.

这篇关于错误,方法不LINQ支持实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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