.net LINQ to Entities 无法识别方法 Int32 get_Item(Int32)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5233054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:20:58  来源:igfitidea点击:

LINQ to Entities does not recognize the method Int32 get_Item(Int32)

.netlinqentity-framework

提问by Murat Güzel

I am a newbie about entity framework and linq. My query is like that

我是实体框架和 linq 的新手。我的查询是这样的

var query = (from d in db.MYTABLE
             where d.RELID.Equals(myInts[0])
             select d.ID).Distinct();

List<int?> urunidleri = query.ToList();

When i execute this code, i got the error message "LINQ to Entities does not recognize the method Int32 get_Item(Int32)". How can i solve my problem ?

当我执行此代码时,我收到错误消息“LINQ to Entities 无法识别方法 Int32 get_Item(Int32)”。我该如何解决我的问题?

Thanks...

谢谢...

回答by John Gietzen

You need to store your intin a variable, so that EntityFramework isn't trying to pull the whole array into its scope.

您需要将您的存储int在一个变量中,以便 EntityFramework 不会试图将整个数组拉入其范围。

var myInt = myInts[0];

var query = (from d in db.MYTABLE
             where d.RELID.Equals(myInt)
             select d.ID).Distinct();

List<int?> urunidleri = query.ToList();

回答by Albin Sunnanbo

var firstInt = myInts[0];
var query = (from d in db.MYTABLE
             where d.RELID.Equals(firstInt)
             select d.ID).Distinct();

List<int?> urunidleri = query.ToList();

回答by ravi saini

The Linq query is ultimately transformed into an SQL query and LINQ doesn't know what to do with Session["UserName"](that gets the "UserName" item).

Linq 查询最终转换为 SQL 查询,而 LINQ 不知道如何处理Session["UserName"](获取“用户名”项)。

A common way to workaround this is just to use a local variable to which you'll assign Session["UserName"]and that you'll use in your Linq query...

解决此问题的一种常见方法是使用您将分配的局部变量Session["UserName"]并将在您的 Linq 查询中使用该变量...

like

喜欢

string loggedUserName = Session["LogedUsername"].ToString();
var userdetail = dc.faculties.Where(a => a.F_UserName.Equals(loggedUserName)).FirstOrDefault();

reference http://mvc4asp.blogspot.in/

参考http://mvc4asp.blogspot.in/