Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ to Entities does not recognize the method 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...

like image 745
Murat Güzel Avatar asked Mar 08 '11 13:03

Murat Güzel


2 Answers

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(); 
like image 160
John Gietzen Avatar answered Oct 23 '22 12:10

John Gietzen


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(); 
like image 42
Albin Sunnanbo Avatar answered Oct 23 '22 10:10

Albin Sunnanbo