LINQ to Entities 无法识别方法 Int32 get_Item(Int32)
我是实体框架和 linq 的新手。我的查询是这样的
var query = (from d in db.MYTABLE
where d.RELID.Equals(myInts[0])
select d.ID).Distinct();
List<int?> urunidleri = query.ToList();
当我执行此代码时,我收到错误消息“LINQ to Entities 无法识别方法 Int32 get_Item(Int32)”。我该如何解决我的问题?
谢谢...
I am a newbie about entity framework and linq. My query is like that
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 ?
Thanks...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要将
int
存储在变量中,以便 EntityFramework 不会尝试将整个数组拉入其范围。You need to store your
int
in a variable, so that EntityFramework isn't trying to pull the whole array into its scope.Linq 查询最终会转换为 SQL 查询,并且 LINQ 不知道如何处理
Session["UserName"]
(获取“UserName”项)。解决此问题的常见方法是使用一个局部变量,您将为其分配 Session["UserName"] 并在 Linq 查询中使用该变量...
例如
参考 http://mvc4asp.blogspot.in/
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).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...like
reference http://mvc4asp.blogspot.in/