I have a service class to hold the calls to the RIA service. I have the following method to save multiple records, on the first step I should get the famous MaxId from the table and increment it in the foreach to add the objects.
public bool SaveRecs(ObservableCollection<Acc> accList)
{
int i = 0;
invokeOperation = Context.GetMaxAcc();
invokeOperation.Completed +=
(s, a) =>
{
foreach (Acc item in accList)
{
//if (CheckAcc(item.name, item.id)) continue;
item.id = invokeOperation.Value + i;
Context.Accs.Add(item);
i++;
}
};
return Commit();
}
The problem is that when the method is called first time, it do nothing and second time it works, the strange is that it may give an error of duplicate. when I debug the code the id was ZERO
Is this the correct way of doing it?
thanks
My mistake, I should move the commit after the foreach.