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

I am new to entity infrastructure and linq. My request is similar to this

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 Int32 method get_Item (Int32)". How can I solve my problem?

Thank...

+47
linq entity-framework
Mar 08 2018-11-11T00:
source share
3 answers

You need to store the int in a variable so that EntityFramework does not try to pull the entire array into 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(); 
+105
Mar 08 2018-11-11T00:
source share
 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(); 
+6
Mar 08 2018-11-11T00:
source share

The Linq query is ultimately converted to an SQL query, and LINQ does not know what to do with Session["UserName"] (which receives the "UserName" element).

A common way around this is to simply use the local variable that you assigned Session["UserName"] , and which you will use in your Linq query ...

as

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

link http://mvc4asp.blogspot.in/

-2
Sep 08 '14 at 15:16
source share



All Articles