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

.NetLinqEntity Framework

.Net Problem Overview


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

.Net Solutions


Solution 1 - .Net

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

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

Solution 2 - .Net

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

Solution 3 - .Net

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

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

reference http://mvc4asp.blogspot.in/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMurat G&#252;zelView Question on Stackoverflow
Solution 1 - .NetJohn GietzenView Answer on Stackoverflow
Solution 2 - .NetAlbin SunnanboView Answer on Stackoverflow
Solution 3 - .Netravi sainiView Answer on Stackoverflow