Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix this ArrayIndex error?

Tags:

c#

asp.net

linq

I would like to fetch datas with checking id with some numbers.

int r = 0;
var ask = from y in entity.sorulars    
          where y.soru_id == questionID[r]
          select new { y.sorutipi_id };

foreach (var hold2 in ask)
{
    questionTypeID[r] = hold2.sorutipi_id;
    r++;
}

I use these codes but

"The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities."

error appears. I guess questionID[r] is not supported in LINQ so what should I type instead of it. Thank you

like image 658
OwnurD Avatar asked Oct 20 '22 17:10

OwnurD


1 Answers

Try this way, declare var Id=questionID[r]; variable globally and pass the id to your query

int r = 0;
var Id= questionID[r];

var ask = from y in entity.sorulars    
          where y.soru_id == Id
          select new { y.sorutipi_id };

foreach (var hold2 in ask)
{
    questionTypeID[r] = hold2.sorutipi_id;
    r++;
}
like image 189
Ramesh Rajendran Avatar answered Nov 01 '22 09:11

Ramesh Rajendran