Hi all I have a code like this inside entityframework (I want to change many items at the same time I dont know whether we can use a loop like this but it throws an exception like this:
LINQ to Entities does not recognize the method 'Int32 get_Item(Int32)' method, and this method cannot be translated into a store expression.
Code:
try
{
for (int j = 0; j < ids.Count; j++)
{
using (OzgorenEntities2 context = new OzgorenEntities2())
{
Stock st = context.Stocks.First(i => i.id == ids[j]);
st.stockAmount = amounts[j];
context.SaveChanges();
}
}
return true;
}
catch (Exception ex)
{
return false;
}
to be honest I searched and only find that converting is not working in server side but I dont convert it there what might be solution for me ?
Thanks
ids[j]as a value in your query. It's totally obvious to you and me that you just want to use a value within the array, but as far as the query provider is concerned, you're trying to access the indexer property calledget_Itemon the array, and it doesn't know how to generate SQL code for that.