Eliminar registros en Wcf Ria

I use wcf ria in silverlight application. in the client side, i use following code to delete some records:

    var installments = context.Installments.Where(i => i.RequestId == selectedRequest.RequestId);
    foreach (var installment in installments)
    {
        context.Installments.Remove(installment);
    }
    context.SubmitChanges();

when run this code i have following error:

Se modificó la colección; Es posible que la operación de enumeración no se ejecute.

how can i fix this problem?!!

preguntado el 09 de marzo de 12 a las 13:03

1 Respuestas

That's happening because you're removing objects from the collection, while you're enumerating it. The easiest way I've found to work around that is to add .ToArray() or .ToList() to the end of your enumeration line. I.e.

var installments = context.Installments.Where(i => i.RequestId == selectedRequest.RequestId).ToArray();

This will give you an enumeration that is "detached" from the original collection.

Espero que esto ayude. Nate

respondido 09 mar '12, 13:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.